自定义时间选择器调用时报错

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了自定义时间选择器调用时报错相关的知识,希望对你有一定的参考价值。

FATAL EXCEPTION: main
Process: droid.gdhktech.com.pubhealthdoc, PID: 8948
java.lang.RuntimeException: Unable to start activity ComponentInfo{droid.gdhktech.com.pubhealthdoc/droid.gdhktech.com.pubhealthdoc.ui.acti.MainActivity}: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:562)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:282)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
at android.widget.PopupWindow.invokePopup(PopupWindow.java:1104)
at android.widget.PopupWindow.showAtLocation(PopupWindow.java:933)
at android.widget.PopupWindow.showAtLocation(PopupWindow.java:897)
at droid.gdhktech.com.pubhealthdoc.ui.widge.BottomPopupWindow.show(BottomPopupWindow.java:85)
at droid.gdhktech.com.pubhealthdoc.ui.acti.MainActivity.initData(MainActivity.java:42)
at cn.droidlover.xdroid.base.XActivity.onCreate(XActivity.java:31)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5254) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 

 

 

解决:不要直接在activity里面调用,要在OnClickListeners里面调用。

以上是关于自定义时间选择器调用时报错的主要内容,如果未能解决你的问题,请参考以下文章

jQuery 自定义选择器,“未定义”

连接sqlserver数据库时报错,请问怎么解决

Android 自定义时间日期选择器?

Android 存储访问框架 - 自定义文件类型的启动选择器

点击自定义 UIView 会触发错误的选择器

如何从 nib 中修复此“在托管对象上调用选择器 ... 已被 GC'ed”,其中包含未使用的自定义 UITableViewCell?