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

"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;

Steve.

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

omg thank you!!

Hello,

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.

Steve.