IllegalArgumentException:视图未附加到窗口管理器。对话框.关闭
我有一个小错误想要摆脱。 我不知道为什么会出现这个错误。 模拟器和测试手机运行完美! 我拥有的唯一信息是我从 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="portrait" 来确保方向不会改变。 但错误仍然存在。
有人可以帮我吗? 这是我使用的代码示例:
final ProgressDialog pd = ProgressDialog.show(this, "Title", "Message", true, false);
new Thread(new Runnable(){
public void run(){
makeHttpRequest();
pd.dimiss();
}
}).start();
I have a little error i want to get rid of.
I have no idea why this error occurs.
The simulator and test phone runs perfect!
The only info I have is the Stacktraces I got from the app users in android Market.
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
First i thought the code below would cause the application to crash if the user change the phone's orientation while the progress dialog is not yet dismissed.
I made shure the orientation would not change by adding: android:screenOrientation="portrait".
But the error is still alive.
Could any one help me out?
This is a code example which i use:
final ProgressDialog pd = ProgressDialog.show(this, "Title", "Message", true, false);
new Thread(new Runnable(){
public void run(){
makeHttpRequest();
pd.dimiss();
}
}).start();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否将
android:screenOrientation="portrait"
放入 Activity 或应用程序中?当对话框未正确关闭时,当活动停止时,也会发生此异常,这意味着您应该在 onPause/onStop 中处理对话框关闭。我曾经遇到过这个问题。Did you put
android:screenOrientation="portrait"
in activity or in appication? also this exception occurs when dialog is not properly dismiss, when activity stops, means you should handle dialog dismiss in onPause/ onStop. I have face this issue once.即使您将方向限制为纵向,锁定屏幕也可能会变为横向,并且您的活动将被重新创建。为了确保对话框被关闭,我会这样做:
另外,当活动被销毁时,您应该关闭对话框:
这为我解决了问题 - 希望它有帮助:)
Even if you restrict the orientation to portrait, the lock screen for example might get into landscape and your activity is recreated. In order to make sure that the dialog gets dismissed, I would do this:
Also, you should dismiss the dialog when the activity is destroyed:
This solved the problem for me - hope it helps :)
试试这个代码:
Try this code: