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 trialJonathan Barnthouse
2,801 PointsHaving trouble with this task, looking for exact code to complete so I can learn.
Challenge Task 1 of 1
This warm-up is intended as a review of previous material. Initialize the member variable exterminateButton using the findViewById() method. The ID for the button is button1. Don't forget to cast the generic View returned by the method!
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
protected Button exterminateButton; // <-- check this name below
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Declare our view variables
mExterminateButton = (Button) findViewById(R.id.button1);
}
}
[MOD: edited code block - srh]
3 Answers
Steve Hunter
57,712 PointsHi Jonathan,
The button variable is called exterminateButton
not mExterminateButton
. It is declared at the top of the class. Change your line of code to reflect that, and the rest looks fine!
exterminateButton = (Button) findViewById(R.id.button1);
^ // no m
Steve.
Thomas Beaudry
29,084 PointsIs it just me or does Ben not even cover what he's asking for in some of his Code Challenges?
Steve Hunter
57,712 PointsI think the material is covered but the challenge may require some lateral thinking to employ the skills and concepts you've learned.
Thomas Beaudry
29,084 PointsHi Steve Hunter, yes I totally agree with you, he's just preparing a linear/refresher challenge taught earlier, I guess I was too complacent & looked to breeze through his Android course...my fault entirely ;)
Steve Hunter
57,712 PointsI don't think it's about blame or fault. Everyone learns differently so the way each course is presented may or may not work optimally for each individual. But there's always lots of support in these Community pages should anything not be going to plan.
Thomas Beaudry
29,084 PointsYes, very thankful for our TH support for sure. My Irascible comment I was referring to being "my fault", happiest of coding's :)
Jonathan Barnthouse
2,801 PointsJonathan Barnthouse
2,801 PointsHi Steve, Thanks for the help. It was a syntax error.... I need to get new glasses:) You're the Best!
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsGlad you got it fixed.