Reputation: 357
I am developing an opencv app for android and am trying to lock my camera's auto exposure. I have been following the tutorial 3 sample in OpenCV4Android in order to access the various camera parameters. I have made a custom camera class for accessing the camera properties.
Full error:
NullPointerException: Attempt to invoke virtual method 'android.hardware.Camera$Parameters
android.hardware.Camera.getParameters() on a null object reference
at {PackageName}.MainView.lockAutoExposure()
This is my MainView class so far (the custom camera class):
public class MainView extends JavaCameraView {
private static final String TAG = "Urop::MainView";
public MainView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@SuppressWarnings("deprecation")
public void lockAutoExposure() {
Camera.Parameters params = mCamera.getParameters();
params.setAutoExposureLock(true);
mCamera.setParameters(params);
}
}
Here is where I instantiate the class and set it up in the main activity:
private MainView mOpenCvCameraView;
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch(status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i(TAG, "Loaded Successfully");
mOpenCvCameraView.enableView();
mOpenCvCameraView.setMaxFrameSize(640, 480);
mOpenCvCameraView.lockAutoExposure();
System.loadLibrary("opencvnative");
break;
}
...
My permissions in the manifest. Not sure if I need anything else:
<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" />
If anyone can help, I would greatly appreciate it!
Upvotes: 1
Views: 286
Reputation: 357
Solved it by moving lockAutoExposure to the onCameraViewStarted() method.
Upvotes: 1
Reputation: 4646
mCamera
is a null object. It is failing because you are trying to call getParameters()
on something that does not exist (unless you are not showing us the full code?)
Upvotes: 0