Johnny.Doe Johnny.Doe - 1 month ago 7
Java Question

Nothing happens if i click the button

My Code

public class start extends AppCompatActivity {
@Override
protected void onCreate(Bundle ici) {
super.onCreate(ici);
setContentView(R.layout.activity_start);


final Button button = (Button) findViewById(R.id.button1);

button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
Intent myIntent = new Intent(start.this, QuestionActivity.class);
start.this.startActivity(myIntent);
}
});



Not sure if it finds the button but ther is no error


final Button button5 = (Button) findViewById(R.id.button5);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
Intent myIntent = new Intent(start.this, QuestionActivity.class);
start.this.startActivity(myIntent);
}
});


}


Nothing happens if I click the Button.

If I just write

Intent myIntent = new Intent(start.this, QuestionActivity.class);
start.this.startActivity(myIntent);


It works.

I am new to programming so please be kind :)

Please help

Answer

check the button name ....

 final Button button5 = (Button) findViewById(R.id.button5);
//  use button5 instead of button below one
button5.setOnClickListener(new View.OnClickListener() {   
        public void onClick(View v){
            Intent myIntent = new Intent(start.this, QuestionActivity.class);
            start.this.startActivity(myIntent);
        }
    });
Comments