AndroidRuntime:FATAL EXCEPTION:main:应用程序已停止错误

时间:2016-09-13 10:05:48

标签: java android opencv

每当我运行应用程序时,我都会收到错误Fatal Exception main。 该应用程序使用opencv 2.4.10它已在一台设备上运行,但它在我的设备上失败了我无法弄清楚为什么会发生这种情况。

我不知道哪个部分代码导致了这个错误:

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)

请任何解决方案都非常感谢。

1 个答案:

答案 0 :(得分:1)

显然正在运行的任务正在使用context OpenCBLoader

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

context相关的问题,即上下文不再有效 。尝试传递getApplicationContext()而不是this

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

考虑一个AMK(安卓内存杀手)由于内存不足而导致service被杀的情况,因为服务在前台活动之前首先被破坏,现在你的服务已经死了,加上this上下文不是因此有效,因此异常