Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,437 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);