joe
joe

Reputation: 51

AndroidRuntime: FATAL EXCEPTION: main : application has stopped error

I get the error Fatal Exception main whenever I run application . the app uses opencv 2.4.10 it has worked on one device and it fails on my device I couldn't figure out why this is happening.

I don't know which part is code is causing this error :

09-13 10:55:30.039 19555-19555/org.blatnik.eyemon E/AndroidRuntime: FATAL EXCEPTION: main
Process: org.blatnik.eyemon, PID: 19555
java.lang.RuntimeException: Unable to start service org.blatnik.eyemon.MainService@66d5693 with Intent { flg=0x10000000 cmp=org.blatnik.eyemon/.MainService }: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4079)
    at android.app.ActivityThread.access$2400(ActivityThread.java:221)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1897)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:158)
    at android.app.ActivityThread.main(ActivityThread.java:7224)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
 Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
    at android.view.ViewRootImpl.setView(ViewRootImpl.java:853)
    at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:337)
    at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
    at android.app.Dialog.show(Dialog.java:350)
    at **org.opencv.android.BaseLoaderCallback.onPackageInstall(BaseLoaderCallback.java:110)
    at org.opencv.android.AsyncServiceHelper.InstallService(AsyncServiceHelper.java:117)
    at org.opencv.android.AsyncServiceHelper.initOpenCV(AsyncServiceHelper.java:33)
    at org.opencv.android.OpenCVLoader.initAsync(OpenCVLoader.java:85)
    at org.blatnik.eyemon.MainService.onStartCommand(MainService.java:140)**
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4062)
    at android.app.ActivityThread.access$2400(ActivityThread.java:221) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1897) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:158) 
    at android.app.ActivityThread.main(ActivityThread.java:7224) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

 

please any solution would be very thankful.

Upvotes: 1

Views: 982

Answers (1)

Pavneet_Singh
Pavneet_Singh

Reputation: 37404

Apparently there is a task running which is using the context here with OpenCBLoader

(!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback)) 

The problem related with context i.e the context is not valid anymore .Try passing getApplicationContext() instead of this

(!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, getApplicationContext(), mLoaderCallback)) 

Consider a case when AMK(android memory killer) kill your service due to memory shortage because service get to destroyed first before foreground activity and now your service is dead, plus the this context is not valid anymore hence Exception

Upvotes: 1

Related Questions