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 #72

Open jaydeepw opened 7 years ago

jaydeepw commented 7 years ago

FATAL EXCEPTION: main Process: com.google.android.cameraview.demo, PID: 5712 java.lang.NullPointerException at com.google.android.cameraview.Camera1.adjustCameraParameters(Camera1.java: 320) at com.google.android.cameraview.Camera1.setAspectRatio(Camera1.java: 164) at com.google.android.cameraview.CameraView.setAspectRatio(CameraView.java: 332) at com.google.android.cameraview.demo.MainActivity.onAspectRatioSelected(MainActivity.java: 221) at com.google.android.cameraview.demo.AspectRatioFragment$1.onClick(AspectRatioFragment.java: 84) at android.support.v7.app.AlertController$AlertParams$3.onItemClick(AlertController.java: 959) at android.widget.AdapterView.performItemClick(AdapterView.java: 302) at android.widget.AbsListView.performItemClick(AbsListView.java: 1196) at android.widget.AbsListView$PerformClick.run(AbsListView.java: 3054) at android.widget.AbsListView$3.run(AbsListView.java: 3812) at android.os.Handler.handleCallback(Handler.java: 733) at android.os.Handler.dispatchMessage(Handler.java: 95) at android.os.Looper.loop(Looper.java: 136) at android.app.ActivityThread.main(ActivityThread.java: 5590) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java: 515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java: 1280) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 1096) at dalvik.system.NativeStart.main(Native Method)

jamesbluecrow commented 7 years ago

Some of our users have been experiencing this when opening the camera in a device Galaxy J3(2016 running Android 5.1.

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.

This PR adds that functionality: https://github.com/google/cameraview/pull/207