gpt4 book ai didi

android - OpenCV初始化异常

转载 作者:行者123 更新时间:2023-12-02 16:42:11 25 4
gpt4 key购买 nike

我在我的android项目上使用OpenCV库。在模拟器上,当我手动安装opencv管理器时,一切正常,但是设备上存在问题(带有Android 2.3.6的Samsung Galaxy S Advance)。当我调用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");
}
}

最佳答案

另外,我不确定到底是什么问题,但是我将该初始化移到了我的主要 Activity 中,并且可以正常工作。

关于android - OpenCV初始化异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14684482/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com