gpt4 book ai didi

android - Eclipse+Linux+OpenCV+Android --java.lang.RuntimeException

转载 作者:太空宇宙 更新时间:2023-11-04 03:40:50 24 4
gpt4 key购买 nike

当我尝试使用 opencv4android 更改 android 相机(Linux 操作系统)的分辨率时,遇到了这个问题。

java.lang.RuntimeException: Unable to start activity ComponentInfo{org.opencv.samples.tutorial2/org.opencv.samples.tutorial2.Tutorial2Activity}: java.lang.NullPointerException

Activity 源代码是:

package org.opencv.samples.tutorial2;

import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;


import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;

public class Tutorial2Activity extends Activity implements CvCameraViewListener2 {
private static final String TAG = "OCVSample::Activity";

private Mat mRgba;
private Mat mIntermediateMat;


private CameraBridgeViewBase mOpenCvCameraView;
private Tutorial2View mOpenCvCameraView1;

private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i(TAG, "OpenCV loaded successfully");

// Load native library after(!) OpenCV initialization
System.loadLibrary("mixed_sample");
mOpenCvCameraView.enableView();

} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};

public Tutorial2Activity() {
Log.i(TAG, "Instantiated new " + this.getClass());
}

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "called onCreate");
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);


setContentView(R.layout.tutorial2_surface_view);



mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial2_activity_surface_view);
//mOpenCvCameraView.setMaxFrameSize(1920, 1080);
mOpenCvCameraView.setCvCameraViewListener(this);
mOpenCvCameraView1.setResolution(1920, 1080);



}



@Override
public void onPause()
{
super.onPause();
if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView();
}

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

public void onDestroy() {
super.onDestroy();
if (mOpenCvCameraView != null)
mOpenCvCameraView.disableView();
}

public void onCameraViewStarted(int width, int height) {
mRgba = new Mat(height, width, CvType.CV_8UC4);
mIntermediateMat = new Mat(height, width, CvType.CV_8UC4);
}

public void onCameraViewStopped() {
mRgba.release();
mIntermediateMat.release();
}

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {

mRgba = inputFrame.rgba();
return mRgba;
}
}

AndroidManifest.xml

<manifest package="org.opencv.samples.tutorial2" android:versionCode="21" android:versionName="2.1"><application android:label="@string/app_name" android:icon="@drawable/icon" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"><activity android:name="Tutorial2Activity" android:label="@string/app_name" android:screenOrientation="landscape" android:configChanges="keyboardHidden|orientation"><intent-filter><action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.LAUNCHER"/></intent-filter></activity></application><supports-screens android:resizeable="true" android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true"/><uses-sdk android:minSdkVersion="8"/><uses-permission android:name="android.permission.CAMERA"/><uses-feature android:name="android.hardware.camera" android:required="false"/><uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/><uses-feature android:name="android.hardware.camera.front" android:required="false"/><uses-feature android:name="android.hardware.camera.front.autofocus" android:required="false"/></manifest>

project.properties 文件是:

# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

android.library.reference.1=../../sdk/java
# Project target.
target=android-19

问题是:

04-18 22:30:47.422: E/AndroidRuntime(12540): FATAL EXCEPTION: main
04-18 22:30:47.422: E/AndroidRuntime(12540): Process: org.opencv.samples.tutorial2, PID: 12540
04-18 22:30:47.422: E/AndroidRuntime(12540): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.opencv.samples.tutorial2/org.opencv.samples.tutorial2.Tutorial2Activity}: java.lang.NullPointerException
04-18 22:30:47.422: E/AndroidRuntime(12540): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2202)
04-18 22:30:47.422: E/AndroidRuntime(12540): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2252)
04-18 22:30:47.422: E/AndroidRuntime(12540): at android.app.ActivityThread.access$800(ActivityThread.java:139)
04-18 22:30:47.422: E/AndroidRuntime(12540): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
04-18 22:30:47.422: E/AndroidRuntime(12540): at android.os.Handler.dispatchMessage(Handler.java:102)
04-18 22:30:47.422: E/AndroidRuntime(12540): at android.os.Looper.loop(Looper.java:136)
04-18 22:30:47.422: E/AndroidRuntime(12540): at android.app.ActivityThread.main(ActivityThread.java:5103)
04-18 22:30:47.422: E/AndroidRuntime(12540): at java.lang.reflect.Method.invokeNative(Native Method)
04-18 22:30:47.422: E/AndroidRuntime(12540): at java.lang.reflect.Method.invoke(Method.java:515)
04-18 22:30:47.422: E/AndroidRuntime(12540): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
04-18 22:30:47.422: E/AndroidRuntime(12540): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
04-18 22:30:47.422: E/AndroidRuntime(12540): at dalvik.system.NativeStart.main(Native Method)
04-18 22:30:47.422: E/AndroidRuntime(12540): Caused by: java.lang.NullPointerException
04-18 22:30:47.422: E/AndroidRuntime(12540): at org.opencv.samples.tutorial2.Tutorial2Activity.onCreate(Tutorial2Activity.java:68)
04-18 22:30:47.422: E/AndroidRuntime(12540): at android.app.Activity.performCreate(Activity.java:5275)
04-18 22:30:47.422: E/AndroidRuntime(12540): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
04-18 22:30:47.422: E/AndroidRuntime(12540): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2166)
04-18 22:30:47.422: E/AndroidRuntime(12540): ... 11 more

请提供一些帮助。谢谢。

最佳答案

第 68 行拼写错误:

mOpenCvCameraView1.setResolution(1920, 1080);

应该是:

mOpenCvCameraView.setResolution(1920, 1080);

关于android - Eclipse+Linux+OpenCV+Android --java.lang.RuntimeException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29718556/

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