“android.view.WindowManager $ BadTokenException:无法添加窗口 - 令牌android.view.ViewRootImpl$W@41d51058无效;”

时间:2015-06-12 19:20:48

标签: android input android-popupwindow

我在PopupWindow中有一个EditText,正确显示,当触摸SoftInput键盘打开时,如果在字段中写入拼写错误的单词,它将有红色下划线,如果触摸,则会发生以下异常

06-12 16:05:46.136: E/AndroidRuntime(10375): android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@41d51058 is not valid; is your activity running?
06-12 16:05:46.136: E/AndroidRuntime(10375):    at android.view.ViewRootImpl.setView(ViewRootImpl.java:769)
06-12 16:05:46.136: E/AndroidRuntime(10375):    at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:278)
06-12 16:05:46.136: E/AndroidRuntime(10375):    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
06-12 16:05:46.136: E/AndroidRuntime(10375):    at android.widget.PopupWindow.invokePopup(PopupWindow.java:1067)
06-12 16:05:46.136: E/AndroidRuntime(10375):    at android.widget.PopupWindow.showAtLocation(PopupWindow.java:891)
06-12 16:05:46.136: E/AndroidRuntime(10375):    at android.widget.PopupWindow.showAtLocation(PopupWindow.java:855)
06-12 16:05:46.136: E/AndroidRuntime(10375):    at android.widget.Editor$PinnedPopupWindow.updatePosition(Editor.java:2722)
06-12 16:05:46.136: E/AndroidRuntime(10375):    at android.widget.Editor$PinnedPopupWindow.show(Editor.java:2670)
06-12 16:05:46.136: E/AndroidRuntime(10375):    at android.widget.Editor$SuggestionsPopupWindow.show(Editor.java:2921)
06-12 16:05:46.136: E/AndroidRuntime(10375):    at android.widget.Editor.showSuggestions(Editor.java:2063)
06-12 16:05:46.136: E/AndroidRuntime(10375):    at android.widget.Editor$1.run(Editor.java:1896)
06-12 16:05:46.136: E/AndroidRuntime(10375):    at android.os.Handler.handleCallback(Handler.java:733)
06-12 16:05:46.136: E/AndroidRuntime(10375):    at android.os.Handler.dispatchMessage(Handler.java:95)
06-12 16:05:46.136: E/AndroidRuntime(10375):    at android.os.Looper.loop(Looper.java:136)
06-12 16:05:46.136: E/AndroidRuntime(10375):    at android.app.ActivityThread.main(ActivityThread.java:5479)
06-12 16:05:46.136: E/AndroidRuntime(10375):    at java.lang.reflect.Method.invokeNative(Native Method)
06-12 16:05:46.136: E/AndroidRuntime(10375):    at java.lang.reflect.Method.invoke(Method.java:515)
06-12 16:05:46.136: E/AndroidRuntime(10375):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
06-12 16:05:46.136: E/AndroidRuntime(10375):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
06-12 16:05:46.136: E/AndroidRuntime(10375):    at dalvik.system.NativeStart.main(Native Method)

我在StackOverflow上发现PopupWindow不能成为其他人的父母,但我无法控制键盘软件使用有效的上下文。

如何避免此错误?

PS:在Android 4.4.2+上发生,其中键盘具有自动拼写检查功能

0 个答案:

没有答案