Button ocClick property error Tip

0 Gary Whitney · October 11, 2016
Here is a little bug I wasn't expecting, when I upgraded to Android Studio 2.2.
1. Write a method to be used for the onClick attribute.
2. Add a Button widget to the layout.
3. Edit the onClick property, in Design view, by selecting from the drop-down in the properties window.
4. Now run the project and you get the error that the method can't be found.
5. Go back to the editor and switch to text view mode.
6, I found the Buttons onClick property contains the method with the Activity name in parenthesis.
android:onClick="onSubmitButtonClicked (OptionsActivity)"
when it should be android:onClick="onSubmitButtonClicked"

Make the correction and the error goes away.

Post a Reply


Oldest  Newest  Rating
0 xenofon karidis · October 11, 2016
Try not to use the onClick attribute in the xml layout file but use the button.setOnClickListener in the java file. Its more safe cos sometimes there are problems with the views that you cant see but android can......i hade the same problem few days ago
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator