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.

CameraX: NullPointerException when trying to record video

See original GitHub issue

I have a simple video recording app set up like this:

VideoCaptureConfig videoCaptureConfig = new VideoCaptureConfig.Builder()
        .setLensFacing(CameraX.LensFacing.BACK)
        .setTargetAspectRatio(new Rational(16, 9))
        .setTargetRotation(viewFinder.getDisplay().getRotation())
        .build();
videoCapture = new VideoCapture(videoCaptureConfig);

CameraX.bindToLifecycle(this, preview, videoCapture);

 videoCapture.startRecording(file, new VideoCapture.OnVideoSavedListener() { ... });

which leads to the following NullPointerException:

    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.media.AudioRecord.startRecording()' on a null object reference
        at androidx.camera.core.VideoCapture.startRecording(VideoCapture.java:262)
        at androidx.camera.core.VideoCapture.startRecording(VideoCapture.java:236)
        at de.twometer.stream.cam.CameraActivity.lambda$onCreate$1$CameraActivity(CameraActivity.java:77)
        at de.twometer.stream.cam.-$$Lambda$CameraActivity$MvEAnqH_74mMgbMAcSbB_pNoJ3k.onClick(Unknown Source:4)
        at android.view.View.performClick(View.java:7352)
        at android.view.View.performClickInternal(View.java:7318)
        at android.view.View.access$3200(View.java:846)
        at android.view.View$PerformClick.run(View.java:27807)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7037)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

I am using CameraX version 1.0.0-alpha04

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

40reactions
Twometercommented, Aug 9, 2019

Nevermind, I am just stupid and forgot to request audio permission.

0reactions
temcguircommented, Sep 23, 2022

androidx.camera.video.VideoCapture should not require the audio permission unless you call PendingRecording.withAudioEnabled().

Please see this guide on how to use the new VideoCapture API.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CameraX: NullPointerException when trying to record video #50
I have a simple video recording app set up like this: VideoCaptureConfig videoCaptureConfig = new VideoCaptureConfig.Builder() .
Read more >
NullPointerException in codelabs Android CameraX tutorial ...
This null pointer exception normally occurs when permissions are not declared properly in AndroidManifest.xml . There doesn't seem to be an ...
Read more >
CameraX crash on ImageCapture.takePhoto() [230454568]
The error means the app take picture after lifecycle goes to stop or ImageCapture is unbound, which is not a valid operation for...
Read more >
Issue with a video capture : NullPointerException
Hello ! I Want to use a sketch running an EXTERNE webcam (a logitech 310c). The sketch runs perfectly well with the built-in...
Read more >
CameraX | Android Developers
Fixed NullPointerException/Surface Abandoned error occurring on some devices when quickly taking photos while unbinding and rebinding use cases rapidly. Fixed ...
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