I'm using the Camera2 sample code in one of my apps from here: https://github.com/googlesamples/android-Camera2Basic/blob/master/Application/src/main/java/com/example/android/camera2basic/Camera2BasicFragment.java
It has been working fine until recently the app crashes on image capturing but only on Google Pixel 2 and Pixel 2 XL devices.
Crash report shows the following:
java.lang.NullPointerException:
at ....Camera2BasicFragment$ImageSaver.run (Camera2BasicFragment.java:935)
at android.os.Handler.handleCallback (Handler.java:873)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loop (Looper.java:193)
at android.os.HandlerThread.run (HandlerThread.java:65)
This is line 935 (ImageSaver class):
ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();
I've tried a few things but I'm unable to test as I do not have a Pixel 2 device. Any suggestions?
Update (05-Nov-2018):
So the logical explanation is that the image being returned from the ImageReader is somehow null:
@Override
public void onImageAvailable(ImageReader reader) {
mBackgroundHandler.post(new ImageSaver(reader.acquireLatestImage(), mFile));
}
Some other posts on SO suggest that the ImageReader format may not be supported. This is the format:
mImageReader = ImageReader.newInstance(largest.getWidth(), largest.getHeight(),
ImageFormat.JPEG, /*maxImages*/2);
But I can't imagine why JPEG would be an unsupported format.
Still looking for an answer!