Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android IllegalArgumentException:视图未附加到窗口管理器。Dialog.discover_Android_Multithreading_Dialog_Dismiss_Illegalargumentexception - Fatal编程技术网

Android IllegalArgumentException:视图未附加到窗口管理器。Dialog.discover

Android IllegalArgumentException:视图未附加到窗口管理器。Dialog.discover,android,multithreading,dialog,dismiss,illegalargumentexception,Android,Multithreading,Dialog,Dismiss,Illegalargumentexception,我有一个小错误,我想摆脱。 我不知道为什么会发生这种错误。 模拟器和测试手机运行完美! 我唯一的信息是我从android Market的应用程序用户那里得到的Stacktraces java.lang.IllegalArgumentException: View not attached to window manager at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:355) at android

我有一个小错误,我想摆脱。 我不知道为什么会发生这种错误。 模拟器和测试手机运行完美! 我唯一的信息是我从android Market的应用程序用户那里得到的Stacktraces

java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:355)
at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:200)
at android.view.Window$LocalWindowManager.removeView(Window.java:432)
at android.app.Dialog.dismissDialog(Dialog.java:278)
at android.app.Dialog.access$000(Dialog.java:71)
at android.app.Dialog$1.run(Dialog.java:111)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method
首先,我认为下面的代码会导致应用程序崩溃,如果用户在进程对话框尚未关闭时更改手机的方向。 我添加了:android:screenOrientation=“肖像”,使舒尔的定位不会改变。 但错误仍然存在

有人能帮我吗? 这是我使用的一个代码示例:

final ProgressDialog pd = ProgressDialog.show(this, "Title", "Message",  true, false);

new Thread(new Runnable(){
public void run(){
    makeHttpRequest();
    pd.dimiss();
}
}).start();
请尝试以下代码:

 update.setTitle(getResources().getString(R.string.app_name));
                update.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                update.setCancelable(true);
                update.setMax(100);
                update.show();


                Thread background = new Thread (new Runnable() {
                       public void run() {
                           try {
                               // enter the code to be run while displaying the progressbar.
                               //
                               // This example is just going to increment the progress bar:
                               // So keep running until the progress value reaches maximum value
                               while (update.getProgress()<= update.getMax()) {
                                   // wait 500ms between each update
                                   Thread.sleep(500);

                                   // active the update handler
                                   progressHandler.sendMessage(progressHandler.obtainMessage());
                               }

                           } catch (java.lang.InterruptedException e) {
                               // if something fails do something smart
                           }
                       }
                    });// start the background thread
                    background.start();
                    if(update.getProgress()== 100)
                       {
                           update.dismiss();
                       }
                }




        })
        .setNegativeButton("No", new DialogInterface.OnClickListener(){
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub

            }
        })
        .show();
update.setTitle(getResources().getString(R.string.app_name));
update.setProgressStyle(ProgressDialog.STYLE_水平);
update.setCancelable(true);
setMax(100);
update.show();
线程背景=新线程(newrunnable(){
公开募捐{
试一试{
//输入显示进度条时要运行的代码。
//
//本例只是增加进度条:
//因此,继续运行,直到进度值达到最大值

而(update.getProgress()您是否将
在“活动”或“应用程序”中?当对话框未正确关闭时也会发生此异常,当“活动”停止时,意味着您应该在“暂停/停止”中处理对话框关闭。我曾经遇到过此问题。

即使您将方向限制为纵向,例如锁屏可能会进入横向,并且您的活动将被重新创建d、 为了确保对话框被取消,我将执行以下操作:

if (dialog != null && dialog.isShowing()) {
    dialog.cancel();
}
此外,当活动被销毁时,应关闭该对话框:

@Override
protected void onDestroy() {    
    if (dialog != null && dialog.isShowing()) {
        dialog.cancel();
    }

    super.onDestroy();
}

这为我解决了问题-希望它能有所帮助:)

我在每项活动中都加入了屏幕定向功能,你还收到同样的问题吗?