Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Simple Android App with Java Basic Android Programming Making a Button Do Something

Michał Juszczuk
Michał Juszczuk
885 Points

Why, in my program the proper form of initialising factTextView is R.id.facttextView instead of R.id.factTextView?

I made everything as it was in toutorial, but Android Studio gave me a tip to write : factTextView = findViewById(R.id.facttextView); - It's working.

factTextView = findViewById(R.id.factTextView); - It's how it's made in toutorial, and it's not working in my case.

Why i had to write it differently, even though variable name is "factTextView" (capital T)?

This is the code: //declare our view variables private TextView factTextView; private Button showFactButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fun_facts);

    // Assign Views from the layout file to the corresponding variables

    factTextView = findViewById(R.id.facttextView);
   showFactButton =findViewById(R.id.showFactbutton);

3 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

You most likely used the name facttextView (lower case t) in your layout. Check your res/layout/activity_main.xml or similar file in that folder.

Michał Juszczuk
Michał Juszczuk
885 Points

Ok, dzięki za odpowiedź.

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fun_facts);

     // Assign the Views form the layout file to the corresponding variables
    factTextView = findViewById(R.id.factTextView);
    showFactButton = findViewById(R.id.showFactButton);