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 Basic Android Programming Accessing Views in Code: Assigning Variables

Masrur Chowdhury
Masrur Chowdhury
1,484 Points

in the codeline mFactTextView = findViewById (R.id.factTextView) factTextView is in red for me. How to fix?

my code is copied word for word as on the video, except factTextView is not recognized by AndroidStudio in this specific line of code.

Kourosh Raeen
Kourosh Raeen
23,732 Points

Take a look at the id of the TextView in the xml file. It should be: android:id="@+id/factTextView"

Marsrur I just ran into this problem and after beating my head trying to figure it out it hit me what was wrong. The (R.id.FactTextView) refers to the actual id you assigned to the text in the design view. If you go to the design view and click on the text that says "Ants grow in size ..." if the id is not set to factTextView you will continue to get the red underlines. My problem was it was set to the default id of "textView" and when i would type the id. the words "factTextView" would not come up and instead just textView". It wasn't until i changed the id to "factTextView" that it would pop up. Hope it makes sense and you figure it out.

1 Answer

check res > layout > activity_fun_facts.xml. (in android view) should have [android:id="@+id/factTextView"] inside of [TextView]

think this as selector in html&css