Truck Whale
Truck Whale

Reputation: 37

Android application force close when clicking on a dialog

I make a dialog that appear when click on close button everything is ok but if suddenly someone click on the body of the dialog the application will force close

final Dialog dialog = new Dialog(context);
    dialog.setContentView(R.layout.activity_exit);
    dialog.setTitle("closing app");

    ImageView image = (ImageView) dialog.findViewById(R.id.id_exit_image);
    image.setImageResource(R.drawable.ic_launcher);

    Button dialogButtonyes = (Button) dialog.findViewById(R.id.id_exit_yes);
    Button dialogButtonno = (Button) dialog.findViewById(R.id.id_exit_no);
    dialogButtonyes.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
            finish();
        }
    });
    dialogButtonno.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
    dialog.show();
};

Where is the fault?

Logcat

FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not find a method title(View) in the activity class     android.view.ContextThemeWrapper for onClick handler on view class android.widget.LinearLayout with id 'LinearLayout1'
at android.view.View$1.onClick(View.java:3825)
at android.view.View.performClick(View.java:4475)
at android.view.View$PerformClick.run(View.java:18786)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5493)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1209)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1025)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoSuchMethodException: title [class android.view.View]
at java.lang.Class.getConstructorOrMethod(Class.java:423)
at java.lang.Class.getMethod(Class.java:787)
at android.view.View$1.onClick(View.java:3818)

Upvotes: 0

Views: 356

Answers (1)

Zielony
Zielony

Reputation: 16537

The exception you're getting is being thrown when you declare a click handler method in xml, but the method doesn't exist in the code.

Upvotes: 1

Related Questions