OpenCV init异常

时间:2013-02-04 10:09:58

标签: android opencv

我在我的android项目中使用OpenCV库。在模拟器上,当我手动安装opencv管理器时一切正常,但我在设备上遇到问题(Samsung Galaxy S Advance with Android 2.3.6)。当我调用initAsync函数时,我得到NullPointerException,但我想我应该收到一条消息,说明找不到OpenCV Manager包,并且可以从google play安装它。

我在LogCat中看到了:

java.lang.RuntimeException: Unable to resume activity java.lang.NullPointerException
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2124)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2139)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1672)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3691)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.android.internal.app.AlertController$AlertParams.<init>(AlertController.java:798)
at android.app.AlertDialog$Builder.<init>(AlertDialog.java:287)
at org.opencv.android.BaseLoaderCallback.onPackageInstall(BaseLoaderCallback.java:90)
at org.opencv.android.AsyncServiceHelper.InstallService(AsyncServiceHelper.java:116)
at org.opencv.android.AsyncServiceHelper.initOpenCV(AsyncServiceHelper.java:31)
at org.opencv.android.OpenCVLoader.initAsync(OpenCVLoader.java:39)
at com.myapp.utils.OpenCV.init(OpenCV.java:51)
at com.myapp.ProcessImageActivity.onResume(ProcessImageActivity.java:199)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1153)
at android.app.Activity.performResume(Activity.java:3858)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2114)

哪里可能有问题?

这是我的ProcessImageActivity的一部分:

public class ProcessImageActivity extends SherlockActivity {
private static final String TAG = "ProcessImageActivity";
public static final String EXTRA_IMAGE = "image";
private ImageView mPhotoView;
private OpenCV mOpenCV;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    int theme = R.style.Theme_Sherlock_Light_ForceOverflow;
    setTheme(theme);

    setContentView(R.layout.processimage);

    mOpenCV = new OpenCV(this);

    Bundle extras = getIntent().getExtras();

    if (extras != null) {
        if (extras.containsKey(EXTRA_IMAGE)) {
            mPhotoPath = extras.getString(EXTRA_IMAGE);
        }
    }

    mPhotoView = (ImageView)findViewById(R.id.photo_view);
}

    @Override
protected void onResume() {
    super.onResume();

    mOpenCV.init();
}
}

和OpenCV类中的init函数:

public void init() {
    if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, mContext, mOpenCVLoaderCallback)) {
        Log.e(TAG, "Cannot connect to OpenCV Manager");
    }
}

1 个答案:

答案 0 :(得分:0)

此外,我不确定究竟是什么问题,但我将初始化移至我的主要活动,并且它有效。