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 (2014) Basic Android Programming Accessing Views in Code

TextView text in red... "Cannot resolve symbol TextView"

Hi there,

Following along with Ben where he is talking about setting "casts" and what I am seeing in my app is not the same in his.

In his code, he has the red squiggly error line, but I do not.

This is the code in question:

TextView factLabel = (TextView) FindViewById(R.id.factTextView);

For me... "TextView" on the left side of the = is showing up as red and "(TextView) FindViewById" on the right side is showing up as red.

Also, when hovering over each of them I get a different popup...

For TextView I get "Cannot resolve symbol 'TextView' "

For (TextView) I get "Cannot resolve symbol 'TextView' "

And for FindViewById I get "Cannot resolve method 'FindViewById(int)' "

Not really sure why I am not getting the same output as Ben...

Hope this makes any sense....

Any help would be great!

Thanks!

5 Answers

Stone Preston
Stone Preston
42,016 Points

you need to import the TextView class. add the following to the top of your file with the other import statements:

import android.widget.TextView;

its important to use auto complete when typing out class names. if you use auto complete the class will auto import for you. if you dont choose the auto complete value, you have to import it manually

Thanks! This fixed the TextView problem but I am still getting "FindViewById" still showing up as red with the same error "Cannot resolve method 'FindViewById(int)' "

Stone Preston
Stone Preston
42,016 Points

dont capitalize the f in find

TextView factLabel = (TextView) findViewById(R.id.factTextView);

method names start with a lower case letter

Annnd Thats it! Of course it's the most simple solution :) Thanks!

make sure you check for your imports and also how you wrote that id in xml.

Erin Leathers
Erin Leathers
3,562 Points

Thank you Preston for the answer I had the same problem , had to import the class as well.

And a big Thank you to Scott for asking the question so I didn't have to !

Stone Preston
Stone Preston
42,016 Points

glad you found it helpful!

If you hover over the red TextView and press Alt and enter it will automatically add it to the imports.