无法恢复活动 - 运行时异常

时间:2014-12-01 10:37:26

标签: android opencv

     @Override
            public void onResume()
            {
                super.onResume();
                OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_7, this, mLoaderCallback);
            }

            public void onDestroy() {
                super.onDestroy();

            }

        private BaseLoaderCallback  mLoaderCallback = new BaseLoaderCallback(this) {
                @Override
                public void onManagerConnected(int status) {
                    switch (status) {
                        case LoaderCallbackInterface.SUCCESS:
                        {

                            Log.i(TAG, "OpenCV loaded successfully...................");
                        }
  } 
                    default:
                    {
                        super.onManagerConnected(status);
                    } break;
                }
            }
        };

这是我的日志

  

0java.lang.RuntimeException:无法恢复活动   {com.example.lowfreq / com.example.lowfreq.Sample}:   android.view.WindowManager $ BadTokenException:无法添加窗口 -   令牌android.os.BinderProxy@41b9aca8无效;是你的活动   运行? 1点   android.app.ActivityThread.performResumeActivity(ActivityThread.java:2814)   2点   android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2843)   3点   android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2278)   4在android.app.ActivityThread.access $ 800(ActivityThread.java:138)   5点   android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1236)   6在android.os.Handler.dispatchMessage(Handler.java:102)7 at   android.os.Looper.loop(Looper.java:149)8 at   android.app.ActivityThread.main(ActivityThread.java:5045)9 at   java.lang.reflect.Method.invokeNative(Native Method)10 at   java.lang.reflect.Method.invoke(Method.java:515)11 at   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:786)   12在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)   13 at dalvik.system.NativeStart.main(Native Method)14Caused by:   android.view.WindowManager $ BadTokenException:无法添加窗口 -   令牌android.os.BinderProxy@41b9aca8无效;是你的活动   运行? 15点到   android.view.ViewRootImpl.setView(ViewRootImpl.java:561)16 at   android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:259)   17点   android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)   18在android.app.Dialog.show(Dialog.java:287)19 at   org.opencv.android.BaseLoaderCallback.onPackageInstall(BaseLoaderCallback.java:110)   20点到   org.opencv.android.AsyncServiceHelper.InstallService(AsyncServiceHelper.java:116)   21点   org.opencv.android.AsyncServiceHelper.initOpenCV(AsyncServiceHelper.java:32)   22 org.opencv.android.OpenCVLoader.initAsync(OpenCVLoader.java:60)   23在com.example.lowfreq.Sample.onResume(Sample.java:189)24 at   android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1194)   25在android.app.Activity.performResume(Activity.java:5315)26 at   android.app.ActivityThread.performResumeActivity(ActivityThread.java:2804)

初始化OPEN CV的方式有什么错误吗?

1 个答案:

答案 0 :(得分:1)

尝试在getApplicationContext()中使用this代替OpenCVLoader.initAsync(..)

原因:Should I use getApplicationContext or Activity.this in a long running AsyncTask