Creating a menu, but one of the two buttons does not work properly

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 registration buttons work, but not the login button. Is there something wrong with my code?

+4
source share
4 answers

The laid out code looks great. What exactly doesn’t work? Did you receive an error message?

Since you mention that it works for 'register', but not for 'login', you can double-check to see if you forgot to add Login to your manifest.

0
source

Is the button with id login_button declared in the main layout? If I had to guess, this button is not declared in the main layout, it is declared somewhere else.

double check if button is declared with id login_button in main layout

0
source

Since you are not posting your logarithmic view, it is very difficult to understand where this problem is. I offer you a few things that you must make sure that they are in place, as he told me. If then do not correct them, and let me know if this will solve your problem or not.

First, you must make sure that you specify a button with the same identifier in the main.xml file. It will look something like this:

 <button android:id="@+id/login_button" > </button> 

Secondly, you must make sure to declare your Login.class in the AndroidManifest.xml file. It will look something like this:

 <application> <activity android:name=".Login"></activity> </application> 

Check if these things are in place or not.

0
source

Have you announced all the actions ?;)

0
source

Source: https://habr.com/ru/post/1379812/


All Articles