Java – Menu created, but one of the two buttons does not work

Menu created, but one of the two buttons does not work… here is a solution to the problem.

Menu created, but one of the two buttons does not work

 public class SuperActivity extends Activity{

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

Button registerButton = (Button) findViewById(R.id.register_button);
         registerButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                 Intent myIntent = new Intent(SuperActivity.this, Register.class);
                 startActivity(myIntent);
            }

});

Button loginButton = (Button) findViewById(R.id.login_button);
         loginButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                 Intent myIntent = new Intent(SuperActivity.this, Login.class);
                 startActivity(myIntent);
            }
         });

}
  }

My sign-up button works, but the sign-in button doesn’t. Is there a problem with my code?

Solution

The published code looks good. What exactly doesn’t work? Do you have a mistake?

Since you mentioned that it works for “registration” but not for “login”, you may want to double-check that you haven’t forgotten to add Login to your list.

Related Problems and Solutions