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 an Interactive Story App (Retired) User Input Finding Views by IDs

Initialize the member variable mExterminateButton using the findViewById() method. The ID for the button is button1. Don

Initialize the member variable mExterminateButton using the findViewById() method. The ID for the button is button1. Don't forget to cast the generic View returned by the method!

I have no idea on how to do this

MainActivity.java
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {

    protected Button mExterminateButton;

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

        // Declare our view variables
      mExterminateButton.cast.findViewById(button1);

    }

}

4 Answers

Temidayo Adelakin
Temidayo Adelakin
17,505 Points

To cast the class, you don't do .cast. If I want to cast the Button class into mExterminateButton, I have to do mExterminateButton = (Button).....

So to solve the question, you need to enter mExterminateButton = (Button) findViewById(R.id.button1);

It's kind of bad that they expect you to do this without ever truly explaining concepts like casting and what findViewByID really does. I've completed all the prior courses for Android but it only superficially glosses over these things and expects you to just type these things that might as well as be gibberish and follow along.

Dean Gladish
Dean Gladish
1,997 Points

Yes, all you need to do is enter exterminateButton = (Button) findViewById(R.id.button1);

thank you very much!

Remember to mark the solution as "Best Answer"!

I looked this up and I was like...I just did that...to find out i had "extermination" not "exterminate" im now realizing how important it is to spell check my code :P