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 trialScott Schopman
4,027 PointsTextView 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
42,016 Pointsyou 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
Stone Preston
42,016 Pointsdont capitalize the f in find
TextView factLabel = (TextView) findViewById(R.id.factTextView);
method names start with a lower case letter
Scott Schopman
4,027 PointsAnnnd Thats it! Of course it's the most simple solution :) Thanks!
danielplaisimnd
6,837 Pointsmake sure you check for your imports and also how you wrote that id in xml.
Erin Leathers
3,562 PointsThank 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
42,016 Pointsglad you found it helpful!
luke walters
844 PointsIf you hover over the red TextView and press Alt and enter it will automatically add it to the imports.
Scott Schopman
4,027 PointsScott Schopman
4,027 PointsThanks! 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)' "