question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NullPointerException com.google.android.cameraview.Camera2 in collectCameraInfo

See original GitHub issue

Summary

Using the latest version of expo-camera, we have bug reports from Redmi Note 9 Pro users for whom our app crashes when they try to take pictures.

Here is the stacktrace we get (from Sentry):

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.Camera2.collectCameraInfo(Camera2.java:700)
    at com.google.android.cameraview.Camera2.start(Camera2.java:281)
    at com.google.android.cameraview.CameraView.start(CameraView.java:284)
    at expo.modules.camera.ExpoCameraView.onHostResume(ExpoCameraView.java:299)
    at expo.modules.adapters.react.services.UIManagerModuleWrapper$3.onHostResume(UIManagerModuleWrapper.java:127)
    at com.facebook.react.bridge.ReactContext$1.run(ReactContext.java:200)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
    at android.os.Looper.loop(Looper.java:224)
    at android.app.ActivityThread.main(ActivityThread.java:7562)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

We’re using Camera2 API (through useCamera2Api prop), but we were unable to reproduce on our side as we don’t have access to this kind of Android device.

More information about the device

  • Device: Redmi Note 9 Pro
  • Model ID: QKQ1.191215.002
  • OS: Android 10

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

bare

What platform(s) does this occur on?

Android

SDK Version (managed workflow only)

No response

Environment

expo-env-info 1.0.2 environment info:
  System:
    OS: macOS 12.3
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 17.7.2 - /opt/homebrew/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 8.5.2 - /opt/homebrew/bin/npm
    Watchman: 2022.03.14.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3
  IDEs:
    Android Studio: Bumblebee 2021.1.1 Patch 2 Bumblebee 2021.1.1 Patch 2
    Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild
  npmPackages:
    expo: ^44.0.0 => 44.0.5
    react: 17.0.1 => 17.0.1
    react-dom: 17.0.1 => 17.0.1
    react-native: 0.64.3 => 0.64.3
    react-native-web: 0.17.1 => 0.17.1
  Expo Workflow: bare

Reproducible demo

https://snack.expo.dev/@martinezleoml/expo-camera---redmi-note-9-pro-crash

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
martinezleomlcommented, Apr 28, 2022

Also happening on Redmi 7A.

0reactions
aramhovsepyancommented, Dec 9, 2022

An ugly workaround is wrapping the crashed code and switching to cameraX on exception.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting NullPointerException in my custom Android camera ...
I'm trying to build my first custom camera-app in Android. On the emulator I get: "Unfortunately, [app name] has stopped".
Read more >
android.hardware.camera2.CameraCharacteristics.get java ...
Best Java code snippets using android.hardware.camera2.CameraCharacteristics.get (Showing top ... origin: google/cameraview ... Camera2.collectCameraInfo().
Read more >
android.hardware.camera2.params.StreamConfigurationMap
This page shows Java code examples of android.hardware.camera2.params. ... Source Project: pixelvisualcorecamera Author: google File: Camera2Controller.java ...
Read more >
NullPointerException - Android Developers
Google uses cookies to deliver its services, to personalize ads, and to analyze traffic. You can adjust your privacy controls anytime in your...
Read more >
Camera2.java example - Javatips.net
package com.google.android.cameraview; import android.annotation. ... CameraCaptureSession; import android.hardware.camera2.CameraCharacteristics ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found