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 Basic Android Programming Accessing Views in Code: Assigning Variables

Umair Khalil
Umair Khalil
5,285 Points

findViewById() isn't working!

When I try to us the findViewById() i get an error message that says im missing the method body, but in the video he doesn't create a method body please help!

Kourosh Raeen
Kourosh Raeen
23,733 Points

Can you post the complete line of code?

3 Answers

Miles Torres
Miles Torres
2,316 Points

You could try and clean the project. I had the same problem. And if that doesn't work, try rebooting your computer.

Umair Khalil
Umair Khalil
5,285 Points

Here is my code Kourosh Raeen :

package com.example.diaded.funfactsproject;

import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.Button; import android.widget.TextView;

public abstract class FunFacts extends AppCompatActivity { //Declaring our view variables private TextView mFactTextView; private Button mShowFactsButton;

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

}
//Assign the views from the layout file to the private fields declared
mFactTextView = (TextView)findViewById(R.id.factTextView);
Kourosh Raeen
Kourosh Raeen
23,733 Points

I'm not sure if your problem is related to this, but how come you've declared the class as abstract? Also, in the videos the class is named FunFactsActivity. Of course, you can name it anything you want, but make sure it is consistent with the rest of your code and is not a typo.