android / android/camera-samples

NullPointerException in CameraFragment

Open
#469 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
5.5k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

Running non-modified camera2.basic sample on emulator, capturing image by "Front JPEG" camera.

```
Process: com.android.example.camera2.basic, PID: 2662
java.lang.NullPointerException
at com.example.android.camera2.basic.fragments.CameraFragment.getFragmentCameraBinding(CameraFragment.kt:79)
at com.example.android.camera2.basic.fragments.CameraFragment.access$getFragmentCameraBinding(CameraFragment.kt:74)
at com.example.android.camera2.basic.fragments.CameraFragment$animationTask$2.invoke$lambda-1$lambda-0(CameraFragment.kt:117)
at com.example.android.camera2.basic.fragments.CameraFragment$animationTask$2.$r8$lambda$kSaIYQrPru2VxvpYHL5tPwU4w3s(Unknown Source:0)
at com.example.android.camera2.basic.fragments.CameraFragment$animationTask$2$$ExternalSyntheticLambda1.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:938)
```

```
class CameraFragment : Fragment() {
/** Android ViewBinding */
private var _fragmentCameraBinding: FragmentCameraBinding? = null
>>> private val fragmentCameraBinding get() = _fragmentCameraBinding!!
```

Luckily Kotlin has !! operator that can be used to get NPE even in Kotlin code :)

Contributor guide

Open the contributing guide

Research direction

Start in CameraFragment.kt around the fragmentCameraBinding getter at line 79 and animationTask around line 117. Reproduce the crash by capturing an image with the emulator's "Front JPEG" camera, then trace why the binding is unavailable when the animation runs. Done means that capture no longer produces the reported NullPointerException.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.