14

我收到了这个崩溃报告:

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)

ZhuangDictActivity 中的第 311 行是下面的 searchProgressDialog.dismiss():

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

这是 ProgressDialog.show:

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

在 WebView 完成加载之前更改方向时发生崩溃。

4

5 回答 5

37

您只是在解雇,而不是检查它是否显示。您必须先检查它:

if (searchProgressDialog != null && searchProgressDialog.isShowing()) {
    searchProgressDialog.dismiss();
}
于 2013-10-22T06:56:11.837 回答
7

请覆盖 onDestroy 方法。

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

    if((progressDialog != null) && progressDialog.isShowing() ){
        progressDialog.dismiss();
    }
}
于 2015-01-22T02:12:01.603 回答
1

这是因为您正在尝试显示进度对话框,但在那一刻您的活动似乎被破坏了......

于 2013-10-22T06:55:45.843 回答
0
       if (mProgressDialog != null) {
        mProgressDialog.dismiss();
        mProgressDialog = null;
    }
于 2013-10-22T07:01:03.493 回答
0

我认为您已经通过代码解除了对话框,并且您正在再次执行此操作。所以请在关闭它之前检查对话框对象是否为空。并将其分配给null。

于 2013-10-22T07:02:00.623 回答