Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!

MainActivity.java
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

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

Steve.

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 :)