Reputation: 10068
I have a problem with android Camera2 API on a Nexus 7. I have developed an app on android 4.4.4 that uses the camera to take a picture, and I want to update it for the Lollipop update. I've followed code from this link to make new camera api work: https://github.com/googlesamples/android-Camera2Basic/blob/master/Application/src/main/java/com/example/android/camera2basic/Camera2BasicFragment.java
I've tested code on a Nexus 5, and everything works well, but if i try it on a Nexus 7, something goes wrong. This is the error log:
12-17 17:01:15.517: W/LegacyRequestMapper(24382): convertRequestMetadata - control.awbRegions setting is not supported, ignoring value
12-17 17:01:15.517: W/LegacyRequestMapper(24382): Only received metering rectangles with weight 0.
12-17 17:01:15.518: W/LegacyRequestMapper(24382): Only received metering rectangles with weight 0.
12-17 17:01:15.519: W/LegacyRequestMapper(24382): mapAeAndFlashMode - Ignore control.aeMode == ON_AUTO_FLASH;camera does not support it
12-17 17:01:15.519: W/LegacyRequestMapper(24382): convertRequestToMetadata - Ignoring android.lens.focusDistance false, only 0.0f is supported
12-17 17:01:15.955: I/CameraDeviceState(24382): Legacy camera service transitioning to state CAPTURING
12-17 17:01:21.198: I/RequestQueue(24382): Repeating capture request cancelled.
12-17 17:01:21.198: I/RequestQueue(24382): Repeating capture request set.
12-17 17:01:21.215: W/LegacyRequestMapper(24382): convertRequestMetadata - control.awbRegions setting is not supported, ignoring value
12-17 17:01:21.215: W/LegacyRequestMapper(24382): Only received metering rectangles with weight 0.
12-17 17:01:21.215: W/LegacyRequestMapper(24382): Only received metering rectangles with weight 0.
12-17 17:01:21.216: W/LegacyRequestMapper(24382): mapAeAndFlashMode - Ignore control.aeMode == ON_AUTO_FLASH;camera does not support it
12-17 17:01:21.216: W/LegacyRequestMapper(24382): convertRequestToMetadata - Ignoring android.lens.focusDistance false, only 0.0f is supported
12-17 17:01:21.495: E/AndroidRuntime(24382): FATAL EXCEPTION: CameraBackground
12-17 17:01:21.495: E/AndroidRuntime(24382): Process: com.example.newapicamera, PID: 24382
12-17 17:01:21.495: E/AndroidRuntime(24382): java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
12-17 17:01:21.495: E/AndroidRuntime(24382): at com.example.newapicamera.Camera2BasicFragment$4.process(Camera2BasicFragment.java:285)
12-17 17:01:21.495: E/AndroidRuntime(24382): at com.example.newapicamera.Camera2BasicFragment$4.onCaptureCompleted(Camera2BasicFragment.java:324)
12-17 17:01:21.495: E/AndroidRuntime(24382): at java.lang.reflect.Method.invoke(Native Method)
12-17 17:01:21.495: E/AndroidRuntime(24382): at java.lang.reflect.Method.invoke(Method.java:372)
12-17 17:01:21.495: E/AndroidRuntime(24382): at android.hardware.camera2.dispatch.InvokeDispatcher.dispatch(InvokeDispatcher.java:39)
12-17 17:01:21.495: E/AndroidRuntime(24382): at android.hardware.camera2.dispatch.HandlerDispatcher$1.run(HandlerDispatcher.java:65)
12-17 17:01:21.495: E/AndroidRuntime(24382): at android.os.Handler.handleCallback(Handler.java:739)
12-17 17:01:21.495: E/AndroidRuntime(24382): at android.os.Handler.dispatchMessage(Handler.java:95)
12-17 17:01:21.495: E/AndroidRuntime(24382): at android.os.Looper.loop(Looper.java:135)
12-17 17:01:21.495: E/AndroidRuntime(24382): at android.os.HandlerThread.run(HandlerThread.java:61)
12-17 17:01:21.542: I/RequestQueue(24382): Repeating capture request cancelled.
12-17 17:01:21.580: E/BufferQueueProducer(24382): [unnamed-24382-2] dequeueBuffer: BufferQueue has been abandoned
12-17 17:01:21.580: E/BufferQueueProducer(24382): [unnamed-24382-2] dequeueBuffer: BufferQueue has been abandoned
12-17 17:01:21.596: E/BufferQueueProducer(24382): [unnamed-24382-2] queueBuffer: BufferQueue has been abandoned
12-17 17:01:21.605: W/Camera-JNI(24382): callback on dead camera object
12-17 17:01:21.620: E/BufferQueueProducer(24382): [unnamed-24382-2] queueBuffer: BufferQueue has been abandoned
12-17 17:01:21.651: E/BufferQueueProducer(24382): [unnamed-24382-2] queueBuffer: BufferQueue has been abandoned
12-17 17:01:21.688: E/BufferQueueProducer(24382): [unnamed-24382-2] queueBuffer: BufferQueue has been abandoned
12-17 17:01:21.721: E/BufferQueueProducer(24382): [unnamed-24382-2] queueBuffer: BufferQueue has been abandoned
The line that throws the exception is:
int aeState = result.get(CaptureResult.CONTROL_AE_STATE);
What is going wrong?
Upvotes: 4
Views: 6404
Reputation: 21756
Before using any feature of Camera2 API, first you need to check if that feature is supported by device or not. For your case, you can check like below:
// CONTROL_AE_STATE can be null on some devices
Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
if (aeState == null ||
aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED) {
mState = STATE_WAITING_NON_PRECAPTURE;
captureStillPicture();
} else {
runPrecaptureSequence();
}
For more details you can check official sample code from Google here: https://github.com/googlesamples/android-Camera2Basic
Upvotes: 2
Reputation: 18097
The Nexus 7 is a LEGACY-level device when using the new camera2 API, and LEGACY devices have many limitations relative to devices that implement either the LIMITED or FULL levels of the new API.
In the documentation for CONTROL_AE_STATE, there's a note:
Limited capability - Present on all camera devices that report being at least HARDWARE_LEVEL_LIMITED devices in the android.info.supportedHardwareLevel key
which means it's not guaranteed to be present for LEGACY devices, and in fact it won't be, as such devices don't produce AE state information.
Upvotes: 4
Reputation: 11
I read today camera2 api is implemented only in nexus 5 and 6 versions of lollipop.
Upvotes: 1
Reputation: 8579
My guess is that result
is a bundle, and get
returns an Integer
object (as opposed to an int
primitive like on the left hand side of the statement). It seems as though the CaptureResult.CONTROL_AE_STATE
is not in the bundle. This may mean that something is not supported on your device, but that is unclear.
The crash occurs because Java is automatically unboxing an Integer
into an int
, but the Integer
here is null
! This will throw a null pointer exception because Java is trying to convert a null object into an int, hence the warning:
Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
A safer way to deal with this is to have aeState
be an Integer
so you don't force java to auto-unbox the right side of the statement. Java is trying to help you out, but it can be confusing!
Upvotes: 0