我的旋转器遇到了很大的问题。我的弹出窗口显示没有任何问题,它显示我的旋转器处于关闭位置。
但是当我打开它时,我的应用程序崩溃并显示以下错误信息...
04-10 08:34:33.773 1690-1690/com.example.paul_io E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.paul_io, PID: 1690
android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@52f02170 is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:532)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:259)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.widget.PopupWindow.invokePopup(PopupWindow.java:1019)
at android.widget.PopupWindow.showAsDropDown(PopupWindow.java:925)
at android.widget.ListPopupWindow.show(ListPopupWindow.java:625)
at android.widget.Spinner$DropdownPopup.show(Spinner.java:1110)
at android.widget.Spinner.performClick(Spinner.java:658)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
我做错了什么?
重要代码:
Variables.mainActivity = MainActivity.this;
.
.
.
Activity mContext = Variables.mainActivity;
Spinner ecb = new Spinner(mContext);
答案 0 :(得分:1)
问题在于您的上下文已通过(BadTokenException
)。
我认为您使用的是getApplicationContext()
。而是使用YourActivityName.this
来传递context