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 User Input Finding Views by IDs

Having 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

    public void onCreate(Bundle savedInstanceState) {
        // Declare our view variables
      mExterminateButton = (Button) findViewById(R.id.button1);       

[MOD: edited code block - srh]

3 Answers

Hi 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


Hi Steve, Thanks for the help. It was a syntax error.... I need to get new glasses:) You're the Best!

Glad you got it fixed. :+1: :wink:

Thomas Beaudry
Thomas Beaudry
29,084 Points

Is it just me or does Ben not even cover what he's asking for in some of his Code Challenges?

I think the material is covered but the challenge may require some lateral thinking to employ the skills and concepts you've learned.

Thomas Beaudry
Thomas Beaudry
29,084 Points

Hi 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 ;)

I 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
Thomas Beaudry
29,084 Points

Yes, very thankful for our TH support for sure. My Irascible comment I was referring to being "my fault", happiest of coding's :)