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 (2014) Basic Android Programming Adding the onClick() Method

My Android Studio cannot recognize factTextView nor showFactButton. It appears red instead of purple. Why is that?

What am I doing wrong? What should I add?

Cathy, Can you show your code for the onCreate class. If its red normally its a problem with the way you assigned the variable.

David, thanks for responding to me, my code is as follows: final TextView factLabel = (TextView) findViewById(R.id.factTextView); Button showFactButton = (Button) findViewById(R.id.showFactButton);

I believe I did exactly what the instructor did in the video, so I'm really unsure why studio can't recognize factTextView and showFactButton.

3 Answers

Cathy, Check the id's in the activity_fun_facts.xml(the layout). In this file check the id's for the button and text view making sure the are spelled the same.

android:id="@+id/factTextView" android:id="@+id/showFact"

Thanks! I think that was the issue, which makes sense.. now my program is having trouble resyncing everything.. so it's still red...

Your welcome, try building a clean project by selecting Build menu and then selecting Clean Project.

If you need any more help please let me know and if this has solved the problem don't forgot to mark best answer so everyone knows the questions has been answered.