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!

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 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,733 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