Java Question Unable to add window -- token null is not valid; is your activity running?

JhoeyBoy

Member
Licensed User
Longtime User
After Updating B4A Ver 10.70 I encountered this error upon compiling, any help, thanks much...



*** Service (starter) Create ***
starter_service_create (java line: 202)
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:1000)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:428)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:118)
at android.app.Dialog.show(Dialog.java:458)
at anywheresoftware.b4a.Msgbox.msgbox(Msgbox.java:186)
at anywheresoftware.b4a.keywords.Common.Msgbox2(Common.java:452)
at anywheresoftware.b4a.keywords.Common.Msgbox(Common.java:431)
at lancer.findpeople.starter._service_create(starter.java:202)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at lancer.findpeople.starter.onCreate(starter.java:56)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:4521)
at android.app.ActivityThread.access$2600(ActivityThread.java:296)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2243)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:8178)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
*** Service (starter) Create ***
starter_service_create (java line: 202)
android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:1000)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:428)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:118)
at android.app.Dialog.show(Dialog.java:458)
at anywheresoftware.b4a.Msgbox.msgbox(Msgbox.java:186)
at anywheresoftware.b4a.keywords.Common.Msgbox2(Common.java:452)
at anywheresoftware.b4a.keywords.Common.Msgbox(Common.java:431)
at lancer.findpeople.starter._service_create(starter.java:202)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at lancer.findpeople.starter.onCreate(starter.java:56)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:4521)
at android.app.ActivityThread.access$2600(ActivityThread.java:296)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2243)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:8178)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
java.lang.RuntimeException: Unable to create service lancer.findpeople.starter: java.lang.RuntimeException: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
at android.app.ActivityThread.handleCreateService(ActivityThread.java:4535)
at android.app.ActivityThread.access$2600(ActivityThread.java:296)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2243)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:8178)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)
Caused by: java.lang.RuntimeException: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:250)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
at lancer.findpeople.starter.onCreate(starter.java:56)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:4521)
... 8 more
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:1000)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:428)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:118)
at android.app.Dialog.show(Dialog.java:458)
at anywheresoftware.b4a.Msgbox.msgbox(Msgbox.java:186)
at anywheresoftware.b4a.keywords.Common.Msgbox2(Common.java:452)
at anywheresoftware.b4a.keywords.Common.Msgbox(Common.java:431)
at lancer.findpeople.starter._service_create(starter.java:202)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
... 11 more
 

Attachments

  • _b4a_error.PNG
    _b4a_error.PNG
    177 KB · Views: 305

josejad

Expert
Licensed User
Longtime User
Hi:

I think is difficult to say without seeing your code.
Can you run it in debug mode and see in what line of your starter service you're getting the error, and post your relevant code.
It seems you're trying to run something from your starter service (create sub) before the activity is running.
 

josejad

Expert
Licensed User
Longtime User
Top