NULL reference exception on takePicture()
See original GitHub issueI only got this error on my Huawei Ascend P7 device and not on a Samsung Galaxy S5. When taking a picture, it crashes.
mTakePicture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mCameraView.isCameraOpened()) {
mCameraView.takePicture();
}
}
});
mCameraView.addCallback(new CameraView.Callback() {
@Override
public void onPictureTaken(CameraView cameraView, byte[] data) {
super.onPictureTaken(cameraView, data);
mListener.onPictureTaken(data); // Custom method to process the data
mCameraView.stop();
getActivity().getSupportFragmentManager().popBackStack();
}
});
When deleting the following line it works, however I need to close the camera fragment.
getActivity().getSupportFragmentManager().popBackStack();
This is the error:
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.hardware.camera2.CameraCaptureSession.capture(android.hardware.camera2.CaptureRequest, android.hardware.camera2.CameraCaptureSession$CaptureCallback, android.os.Handler)' on a null object reference
at com.google.android.cameraview.Camera2.unlockFocus(Camera2.java:625)
at com.google.android.cameraview.Camera2.access$900(Camera2.java:45)
at com.google.android.cameraview.Camera2$6.onCaptureCompleted(Camera2.java:609)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at android.hardware.camera2.dispatch.InvokeDispatcher.dispatch(InvokeDispatcher.java:39)
at android.hardware.camera2.dispatch.HandlerDispatcher$1.run(HandlerDispatcher.java:65)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5569)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:931)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:726)
My guess is that I need to listen to another callback before killing the camera, but I couldn’t find one.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:11
- Comments:11
Top Results From Across the Web
camera.takePicture null pointer exception - Stack Overflow
I think camera is null in your onClick() function because there is no guaranteed path in onCreate() to create the camera . Modify...
Read more >CameraX crash on ImageCapture.takePhoto() [230454568]
getCameraInfoInternal()' on a null object reference ... DESCRIPTION: This is happening when takePicture() is called on the image capture.
Read more >NullReferenceException Class (System) - Microsoft Learn
The exception that is thrown when there is an attempt to dereference a null object reference.
Read more >CineMachine null reference exception on accessing brain ...
brain.ActiveVirtualCamera isn't valid at Awake() time. It only gets set after LateUpdate().
Read more >image_picker | Flutter Package - Pub.dev
Handling MainActivity destruction on Android # ; void> getLostData() async ; await picker.retrieveLostData(); if ; if (response.files != null) ; final XFile file...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Really work for me!!!!
Just added
to method unlockFocus() in Camera2.java class Dirty trick, but works.