我开发了一个Android应用程序。它在具有4.4版的手机中可以正常工作,但是当我在具有2.2版的手机上运行它时,会显示以下错误消息。
有人可以帮我吗
11-21 13:53:14.679: E/WindowManager(29791): Activity com.example.smart_survey.QR has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@406b9460 that was originally added here
11-21 13:53:14.679: E/WindowManager(29791): android.view.WindowLeaked: Activity com.example.smart_survey.QR has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@406b9460 that was originally added here
11-21 13:53:14.679: E/WindowManager(29791): at android.view.ViewRoot.<init>(ViewRoot.java:263)
11-21 13:53:14.679: E/WindowManager(29791): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:171)
11-21 13:53:14.679: E/WindowManager(29791): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:114)
11-21 13:53:14.679: E/WindowManager(29791): at android.view.Window$LocalWindowManager.addView(Window.java:424)
11-21 13:53:14.679: E/WindowManager(29791): at android.app.Dialog.show(Dialog.java:241)
11-21 13:53:14.679: E/WindowManager(29791): at com.example.smart_survey.QR$Logs.onPreExecute(QR.java:362)
11-21 13:53:14.679: E/WindowManager(29791): at android.os.AsyncTask.execute(AsyncTask.java:391)
11-21 13:53:14.679: E/WindowManager(29791): at com.example.smart_survey.QR$UpdateScore.onPostExecute(QR.java:255)
11-21 13:53:14.679: E/WindowManager(29791): at com.example.smart_survey.QR$UpdateScore.onPostExecute(QR.java:1)
11-21 13:53:14.679: E/WindowManager(29791): at android.os.AsyncTask.finish(AsyncTask.java:417)
11-21 13:53:14.679: E/WindowManager(29791): at android.os.AsyncTask.access$300(AsyncTask.java:127)
11-21 13:53:14.679: E/WindowManager(29791): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
11-21 13:53:14.679: E/WindowManager(29791): at android.os.Handler.dispatchMessage(Handler.java:99)
11-21 13:53:14.679: E/WindowManager(29791): at android.os.Looper.loop(Looper.java:130)
11-21 13:53:14.679: E/WindowManager(29791): at android.app.ActivityThread.main(ActivityThread.java:3687)
11-21 13:53:14.679: E/WindowManager(29791): at java.lang.reflect.Method.invokeNative(Native Method)
11-21 13:53:14.679: E/WindowManager(29791): at java.lang.reflect.Method.invoke(Method.java:507)
11-21 13:53:14.679: E/WindowManager(29791): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
11-21 13:53:14.679: E/WindowManager(29791): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
11-21 13:53:14.773: E/AndroidRuntime(29791): FATAL EXCEPTION: main
11-21 13:53:14.773: E/AndroidRuntime(29791): java.lang.IllegalArgumentException: View not attached to window manager
11-21 13:53:14.773: E/AndroidRuntime(29791): at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:378)
11-21 13:53:14.773: E/AndroidRuntime(29791): at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:223)
11-21 13:53:14.773: E/AndroidRuntime(29791): at android.view.Window$LocalWindowManager.removeView(Window.java:432)
11-21 13:53:14.773: E/AndroidRuntime(29791): at android.app.Dialog.dismissDialog(Dialog.java:278)
11-21 13:53:14.773: E/AndroidRuntime(29791): at android.app.Dialog.access$000(Dialog.java:71)
11-21 13:53:14.773: E/AndroidRuntime(29791): at android.app.Dialog$1.run(Dialog.java:111)
11-21 13:53:14.773: E/AndroidRuntime(29791): at android.app.Dialog.dismiss(Dialog.java:268)
11-21 13:53:14.773: E/AndroidRuntime(29791): at com.example.smart_survey.QR$Logs.onPostExecute(QR.java:420)
11-21 13:53:14.773: E/AndroidRuntime(29791): at com.example.smart_survey.QR$Logs.onPostExecute(QR.java:1)
11-21 13:53:14.773: E/AndroidRuntime(29791): at android.os.AsyncTask.finish(AsyncTask.java:417)
11-21 13:53:14.773: E/AndroidRuntime(29791): at android.os.AsyncTask.access$300(AsyncTask.java:127)
11-21 13:53:14.773: E/AndroidRuntime(29791): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
11-21 13:53:14.773: E/AndroidRuntime(29791): at android.os.Handler.dispatchMessage(Handler.java:99)
11-21 13:53:14.773: E/AndroidRuntime(29791): at android.os.Looper.loop(Looper.java:130)
11-21 13:53:14.773: E/AndroidRuntime(29791): at android.app.ActivityThread.main(ActivityThread.java:3687)
11-21 13:53:14.773: E/AndroidRuntime(29791): at java.lang.reflect.Method.invokeNative(Native Method)
11-21 13:53:14.773: E/AndroidRuntime(29791): at java.lang.reflect.Method.invoke(Method.java:507)
11-21 13:53:14.773: E/AndroidRuntime(29791): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
11-21 13:53:14.773: E/AndroidRuntime(29791): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
11-21 13:53:14.773: E/AndroidRuntime(29791): at dalvik.system.NativeStart.main(Native Method)
最佳答案
pDialog = new ProgressDialog(QR.this); pDialog.setMessage("Loading. Please wait..."); pDialog.setIndeterminate(false); pDialog.setCancelable(false);
将其放在OnCreate方法中,只需在Preexecute中调用pDialog.show()并在onPostExecute()中调用pDialog.dismiss()即可,而无需更改OnStop()
关于java - Android 2.2版的错误对话框,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27062113/