我已经查看了有关AlertDialog此例外的每篇文章,并花了2天时间来追踪问题,但无法解决。谁能看到我想念的东西?
Popup正在从Fragment中显示并具有Parent-Activity的上下文。
IBinder token = rootView.getWindowToken(); //not null
mWindow.showAtLocation(rootView, Gravity.NO_GRAVITY, xPos, yPos);
统计跟踪:
11-24 10:12:18.937: W/System.err(13061): android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@46b62c00 is not valid; is your activity
running?
11-24 10:12:18.937: W/System.err(13061): at android.view.ViewRootImpl.setView(ViewRootImpl.java:563)
11-24 10:12:18.937: W/System.err(13061): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:269)
11-24 10:12:18.937: W/System.err(13061): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
11-24 10:12:18.947: W/System.err(13061): at android.widget.PopupWindow.invokePopup(PopupWindow.java:1041)
11-24 10:12:18.947: W/System.err(13061): at android.widget.PopupWindow.showAtLocation(PopupWindow.java:877)
11-24 10:12:18.947: W/System.err(13061): at android.widget.PopupWindow.showAtLocation(PopupWindow.java:841)
11-24 10:12:18.947: W/System.err(13061): at com.test.hpi.DisplayPopup.displayPopup(DisplayPopup.java:181)
11-24 10:12:18.947: W/System.err(13061): at com.test.hpi.AddModifyAllergypopup.showdropdownlist(AddModifyAllergypopup.java:1038)
11-24 10:12:18.957: W/System.err(13061): at com.test.hpi.AddModifyAllergypopup.access$35(AddModifyAllergypopup.java:999)
11-24 10:12:18.957: W/System.err(13061): at com.test.hpi.AddModifyAllergypopup$9.onClick(AddModifyAllergypopup.java:348)
11-24 10:12:18.957: W/System.err(13061): at android.view.View.performClick(View.java:4421)
11-24 10:12:18.957: W/System.err(13061): at android.view.View$PerformClick.run(View.java:17903)
11-24 10:12:18.957: W/System.err(13061): at android.os.Handler.handleCallback(Handler.java:730)
11-24 10:12:18.967: W/System.err(13061): at android.os.Handler.dispatchMessage(Handler.java:92)
11-24 10:12:18.967: W/System.err(13061): at android.os.Looper.loop(Looper.java:213)
11-24 10:12:18.967: W/System.err(13061): at android.app.ActivityThread.main(ActivityThread.java:5225)
11-24 10:12:18.967: W/System.err(13061): at java.lang.reflect.Method.invokeNative(Native Method)
11-24 10:12:18.967: W/System.err(13061): at java.lang.reflect.Method.invoke(Method.java:525)
11-24 10:12:18.967: W/System.err(13061): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741)
11-24 10:12:18.977: W/System.err(13061): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
11-24 10:12:18.977: W/System.err(13061): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:2)
好的,我让它成功了:))
RootView必须是DialogWindow必须打开的视图,
我以rootView
传递了错误的视图