The method has an incorrect signature

Despite the fact that the onButtonHomeClick method is declared in the Java MainActivity file, when I try to reference this method in XML, I get an error: "The onButtonHomeClick method in MainActivity has an incorrect signature." Both of them are lower, and for my life I can’t understand why it returns such an error, especially since, trying to go to the declaration, pressing Ctrl, clicking on the ButtonHomeClick in the XML file, it will switch to the Java class method. <w> And he is definitely trying to find this method, since Android Monitor returns a fatal error when trying to assign button behavior.

<!-- XML file --> <item android:id="@+id/button_home" android:orderInCategory="100" android:icon="@drawable/home" android:title="Home" android:onClick="onButtonHomeClick" app:showAsAction="always" /> //Java method public void onButtonHomeClick(View v){ Intent intent = new Intent(this, MainActivity.class); } 
+5
source share
3 answers

Delete the project and make sure that the onButtonHomeClick () method is declared as public void .

+2
source

you need to add startActivity(intent); into your method, so it should be something like this:

 public void onButtonHomeClick(View v){ Intent intent = new Intent(this, MainActivity.class); startActivity(intent); } 

I tried using your code with startActivity(intent); and it works great

0
source

Did you remember to include the import for the View class in your MainActvity.java file? (It is not imported by default.)

 import android.view.View; 
-1
source

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


All Articles