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

Markus Henze
Markus Henze
1,798 Points

factTextView stays red

nFactTextView = (TextView)findViewById(R.id.factTextView); When I put the cursor over iy I get the error "Cannot resolve symbol factTextView"

4 Answers

Make sure you gave your view that exact id in the layout xml file. if that checks out, try going to Build->Clean Project and see if that clears it up.

also I notice you wrote nFactTextView. the convention is to use a lowercase m in front, and that's how it is in the video, so just make sure those match. (sidenote: the lower case m is short for "member variable" which tells us that the variable is a member of the main class, rather than whatever function it's being used in).

April Carter
April Carter
15,568 Points

I just figured out why I was having this same problem and how to fix it. Go back to "Creating the Screen Layout" and re-watch the "adding a button" video. towards the end, make sure you follow the steps for "refactoring." I didn't the first time that I watched the videos because it was late and I thought that I would do it the next time I picked up the course. Hopefully that fixes the problem for you too.

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

Markus Henze
Markus Henze
1,798 Points

I already figured it out, thanks for the n I used refactor to change it to a m its good I did that sooner than latter.