简体   繁体   中英

Android - Alert Dialog Force Close error

I have googled a lot and didnt find the solution. I am using alert dialog with Email EditText and two buttons Submit and Cancel and based on the conditions i need to show different alerts. but im getting force close error and logcat shows:

        05-16 13:16:48.281: E/AndroidRuntime(13572): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
05-16 13:16:48.281: E/AndroidRuntime(13572):    at android.view.ViewGroup.addViewInner(ViewGroup.java:1976)
05-16 13:16:48.281: E/AndroidRuntime(13572):    at android.view.ViewGroup.addView(ViewGroup.java:1871)
05-16 13:16:48.281: E/AndroidRuntime(13572):    at android.view.ViewGroup.addView(ViewGroup.java:1851)

and below is the code to display alert dialogs with in the alert dialogs:

forgotPasswordMailAlert() is :

private void forgotPasswordMailAlert(String AlertText)
    {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);

    builder.setMessage(AlertText)
       .setCancelable(true)
       .setPositiveButton("OK", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
            dialog.dismiss();
           }
       });
    AlertDialog alert = builder.create();
    alert.show();
    }

I searched a lot in Stackoverflow as well. Can u please help me where i need to change the code. Please help me how to resolve this issue.

Use alert.dismiss(); instead of dialog.dismiss();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM