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 trialElias Baruch
Courses Plus Student 910 PointsInitialize 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
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
17,505 PointsTo 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);
Eman Tsal
836 PointsIt'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
1,997 PointsYes, all you need to do is enter exterminateButton = (Button) findViewById(R.id.button1);
Elias Baruch
Courses Plus Student 910 Pointsthank you very much!
Alex Alexander
5,673 PointsRemember to mark the solution as "Best Answer"!
Temidayo Adelakin
17,505 Pointsno problem. happy to help.
Andy Hammond
5,415 PointsI 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