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

"Cannot resolve method 'findViewById(int)'" in FunFacts app

Typed in everything exactly as he has in the video; everything is in the "import" section. This still keeps throwing back the error, and the Alt+Enter suggestions are to:

  • Add qualifier factLabel to method
  • Create method 'findViewById'
  • Split into declaration and assignment.
        //Declare our View variables and assign them the Views from the layout file
        TextView factLabel = (TextView) findViewById(R.id.factTextView);
        Button showFactButton;

Copying and pasting from the code challenge threw out the same error. Everything else appears fine except that. Thanks!

If it matters, I'm using the newest version of Android Studio.

3 Answers

Hi there,

Do you definitely have the following import in that file:

import android.widget.TextView;


Sadly, Steve Hunter, I definitely do. Just double-checked -- actually, quintuple-checked probably, by this point. :-( Good thought, though -- thanks!

omg thank you!!


Is your class extending some form of Activity or View? I believe findViewById is only a part of the View and Activity classes and their descendents. If you are doing so, we'd need to see more of your code to be able to track down this issue fully.

That's a great idea. Good work!

Can you push your project to Github or Zip the project and email it to me? I'll replicate the error here, as that's unlikely to be a local issue, and see what the fix is.