OpenCV 初始化异常



我正在我的安卓项目上使用OpenCV库。在模拟器上,当我手动安装opencv管理器时一切正常,但是我在设备上遇到了问题(三星Galaxy S Advance与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 类中的初始化函数:

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

我也不确定到底出了什么问题,但我将该初始化移到了我的主要活动中并且它有效。

相关内容

  • 没有找到相关文章

最新更新