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

Find view by Id

I don't know what's wrong with my coding

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

public class MainActivity extends AppCompatActivity {

    protected Button exterminateButton;

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

        // Declare our view variables
 exterminateButton= (Button)findViewById (R.id.exterminateButton ) ;      
    }

}

Can you copy in your XML code too? That's where the R.id. is pointing.

Thanks,

Steve.

3 Answers

Hi. The instructions say "the ID for the button is button1 " It looks like you put the wrong id there. Correct it and you should be good to go :)

Still don't get it.

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    protected Button exterminateButton;

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

        // Declare our view variables
     exterminateButton1= (Button)findViewById (R.id.exterminateButton1 ) ;

[MOD: edited code block]

You are not calling the view with the id button1 in your code, but a view with another id. Just make sure you use the correct id, as per the instructions. If you're still a bit unsure as to what an id is and how to use it, just re-watch the video and follow the same steps here.

Sorry if I don't serve you the answer on a plate here, but I'm a firm believer in the fact that solving it yourself with a little clue will be more helpful to you in the future. I hope you understand :)

:+1: :smile: