I have a problem with a button on android. I need to create an exit button, but when the button is selected an error appears.
This is the Dashboard class:
public class Dashboard extends Activity {
@Override
protected void onCreate(Bundle saveInstanceState) {
super.onCreate(saveInstanceState);
setContentView(R.layout.layout_dashboard);
}
public void sairApp(View view){
this.finish();
}
}
This is the button:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="80dp"
android:clickable="true"
android:drawableTop="@drawable/sair"
android:onClick="sairApp"
android:text="@string/sair"
android:textColor="#062f3c"
android:textStyle="bold"/>
This is the error:
java.lang.IllegalStateException: Could not find method sairApp(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.widget.Button
at android.view.View$DeclaredOnClickListener.resolveMethod(View.java:4506)
at android.view.View$DeclaredOnClickListener.onClick(View.java:4470)
at android.view.View.performClick(View.java:5225)
at android.view.View$PerformClick.run(View.java:21195)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5451)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)