google / cameraview

[DEPRECATED] Easily integrate Camera features into your Android app
Apache License 2.0
4.74k stars 1.03k forks source link

Nullpointer when setting picture size parameter in Camera1 #207

Open jamesbluecrow opened 6 years ago

jamesbluecrow commented 6 years ago

The camera crashes in some devices running Android 5.1. This is the issue to track it: https://github.com/google/cameraview/issues/72

Caused by java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.SortedSet.last()' on a null object reference
       at com.google.android.cameraview.Camera1.adjustCameraParameters(Camera1.java:349)
       at com.google.android.cameraview.Camera1.setAspectRatio(Camera1.java:168)
       at com.google.android.cameraview.CameraView.setAspectRatio(CameraView.java:335)

The reason is that we try to access the last PictureSizes item for an AspectRatio and there is no such size for that aspect ratio.

In those case we should be defaulting to the PreviewSizes