Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IllegalArgumentException in ProgressDialog.dismiss

Tags:

android

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.

like image 949
user2872856 Avatar asked Oct 22 '13 06:10

user2872856


3 Answers

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();
}
like image 166
kalyan pvs Avatar answered Nov 02 '22 16:11

kalyan pvs


Please override the onDestroy method.

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

    if((progressDialog != null) && progressDialog.isShowing() ){
        progressDialog.dismiss();
    }
}
like image 30
JeasonWong Avatar answered Nov 02 '22 18:11

JeasonWong


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

like image 1
Amit Gupta Avatar answered Nov 02 '22 16:11

Amit Gupta