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

It doesn't say showfactTextView

The showTextView is in red

     //Declare our view variables and assign the the Views from the layout file
    TextView factLabel = findViewById(R.id.showfactTextView);

5 Answers

Hi Jared,

Simply go to your layout.xml file where you design the layout and check if the id of the TextView under consideration is called showfactTextView , if it's in red then it doesn't probably match with the id in your xml file. Both should have the same name

Paolo Scamardella
Paolo Scamardella
24,828 Points

I'm not sure if Gunjeet Hatter answered the question, but do not forget to add the cast (TextView) before findViewById like: TextView factLabel = (TextView) findViewById(R,id,showfactTextView);

Oh my bad! Glad you observed Paolo. Thanks. Yes Jared, you need to add a cast too.

It is still in red

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_stupidfactsftw);

        //Declare our view variables and assign the the Views from the layout file
        TextView factLabel = (TextView)findViewById(R.id.showfactTextView);
        Button showFactButton;

The showfactTextView is in red

Can you paste the textView xml code from activity layout file here? Also did you try to clean the project?

This is the error

Error:(21, 47) error: cannot find symbol variable factTextView