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 (retired 2014) Getting Started with Android Adding an OnClickListener to a Button

Sergio Diaz
Sergio Diaz
511 Points

My Code Won't Work

public class MainActivity extends ActionBarActivity {

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

    TextView answerLabel = (TextView) findViewById(R.id.textView1);
    Button getanswerClick = (Button) findViewById(R.id.button1);


}

Above is the code that I wrote in eclipse. Eclipse sends me an error that says:

"textView1 cannot be resolved or is not a feild" "button1 cannot be resolved or is not a feild"

I double checked to make sure that button1 was the label for my button and that textView1 was the label for my textview

1 Answer

Ben Junya
Ben Junya
12,365 Points

Sometimes Android does this super annoying thing when it doesn't register the labels for textviews. You've got a couple of options here:

1 (quick, but not guaranteed) Under "Project," click "Clean." and select your project. This will get rid of all the previous builds of your project that may be throwing errors. However, this may not solve all problems. It has to do with the errors from the updates being pushed by the Android SDK. You may want to try updating the SDK too. That may fix your problems, but again, it's not guaranteed.

2(slow, but guaranteed) Go use Android Studio. I jumped ship from Eclipse about 6 weeks ago and haven't looked back. Eclipse support is beginning to die out. While I loved Eclipse, and I enjoyed learning it, support is dying, and if you're looking to code more in the future, then Android Studio is going to be the official IDE of choice.