user2872856
user2872856

Reputation: 2051

IllegalArgumentException in ProgressDialog.dismiss

I received this crash report:

java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:395)
at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:239)
at android.view.Window$LocalWindowManager.removeView(Window.java:441)
at android.app.Dialog.dismissDialog(Dialog.java:306)
at android.app.Dialog.access$000(Dialog.java:89)
at android.app.Dialog$1.run(Dialog.java:132)
at android.app.Dialog.dismiss(Dialog.java:296)
at ZhuangDictActivity$1.onPageFinished(ZhuangDictActivity.java:311)
at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:299)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4385)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
at dalvik.system.NativeStart.main(Native Method)

Line 311 in ZhuangDictActivity is searchProgressDialog.dismiss() below:

public void onPageFinished(WebView view, String url) {
                    searchProgressDialog.dismiss();
                    onConfigurationChanged(ZhuangDictActivity.this.getResources().getConfiguration());
                    super.onPageFinished(view, url);
                }

This is the ProgressDialog.show:

public void onPageStarted(WebView view, String url,
                        Bitmap favicon) {
                    searchProgressDialog.setMessage("Loading");
                    searchProgressDialog.show();
                    super.onPageStarted(view, url, favicon);
                }

The crash occurred when the orientation is changed before the WebView finish loading.

Upvotes: 15

Views: 12242

Answers (5)

JeasonWong
JeasonWong

Reputation: 79

Please override the onDestroy method.

@Override
protected void onDestroy() {
    super.onDestroy();

    if((progressDialog != null) && progressDialog.isShowing() ){
        progressDialog.dismiss();
    }
}

Upvotes: 7

kalyan pvs
kalyan pvs

Reputation: 14590

You are simply dismissing, not checking whether it is showing or not. You'll have to check it first:

if (searchProgressDialog != null && searchProgressDialog.isShowing()) {
    searchProgressDialog.dismiss();
}

Upvotes: 37

Sino
Sino

Reputation: 886

I think you have already dismissed the dialog through code, and you are doing it again. So please check whether dialog object is null or not before dismissing it. And assign it to null.

Upvotes: 0

Shivang Trivedi
Shivang Trivedi

Reputation: 2182

       if (mProgressDialog != null) {
        mProgressDialog.dismiss();
        mProgressDialog = null;
    }

Upvotes: 0

Amit Gupta
Amit Gupta

Reputation: 8939

Its is because you are trying to show progress dialog ,but at that moment your activity seems to be destroy...

Upvotes: 1

Related Questions