Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Simple Android App (2014) Basic Android Programming Accessing Views in Code

Can not resolve symbol occur.

When I wrote out the Textview and Button it become red what does this mean how do I fix it and it says cannot resolve symbol when i place my mouse on on Textview and button bellow I copy and paste the code.

// Declare our View variables and assign them the Views from the layout file
        Textview factLabel = findViewById();
    }   Button showFactButton;

2 Answers

Hi,

Your TextView has a few issues:

  • You've mistyped TextView - it needs a capital V
  • The returned value from the findViewById() needs casting; add (TextView) before findViewById
  • Last, you need to reference the id. That is probably something like R.id.factLabel or something

Your button code will need something similar too.

You'll end up with something similar to:

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

Steve.

Also if you are getting a cannot resolve symbol error from the TextView and/or Button, sometimes you just need to organize your imports so that TextView and Button are imported into the class. Once you include those imports they should turn from red to green.