From 4b52bc88788b113f8b21e8c64701ff3802d5cab5 Mon Sep 17 00:00:00 2001 From: NashLegend Date: Mon, 19 Sep 2016 17:24:51 +0800 Subject: [PATCH] StreamConfigurationMap.getHighResolutionOutputSizes() may returns null and cause NPE --- .../camera2/com/google/android/cameraview/Camera2.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/library/src/main/camera2/com/google/android/cameraview/Camera2.java b/library/src/main/camera2/com/google/android/cameraview/Camera2.java index dc220162..f9ee33ba 100644 --- a/library/src/main/camera2/com/google/android/cameraview/Camera2.java +++ b/library/src/main/camera2/com/google/android/cameraview/Camera2.java @@ -424,8 +424,11 @@ private void collectCameraInfo() { mPictureSizes.clear(); // try to get hi-res output sizes for Marshmellow and higher if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - for (android.util.Size size : map.getHighResolutionOutputSizes(ImageFormat.JPEG)) { - mPictureSizes.add(new Size(size.getWidth(), size.getHeight())); + android.util.Size[] outputSizes = map.getHighResolutionOutputSizes(ImageFormat.JPEG); + if (outputSizes != null) { + for (android.util.Size size : map.getHighResolutionOutputSizes(ImageFormat.JPEG)) { + mPictureSizes.add(new Size(size.getWidth(), size.getHeight())); + } } } // fallback camera sizes and lower than Marshmellow