Attempt to Invoke virtual method 'void.setDefaultBufferSize on a null object reference

Asked 2 years ago, Updated 2 years ago, 149 views

https://github.com/yabushi/TimeStampCamera

When you attempt to RUN the

java.lang.NullPointerException: Attempt to Invoke virtual method 'void android.graphics.SurfaceTexture.setDefaultBufferSize(int, int)' on an all object reference
        at com.example.shigeki.timestampcamera.MainActivity.createCameraPreviewSession (MainActivity.java:166)
        at com.example.shigeki.timestampcamera.MainActivity.access$000(MainActivity.java:32)
        at com.example.shigeki.timestampcamera.MainActivity$1.onOpened (MainActivity.java:88)
        at android.hardware.camera2.impl.CameraDeviceImpl $1.run (CameraDeviceImpl.java:118)
        at android.os.Handler.handleCallback (Handler.java:810)
        at android.os.Handler.dispatchMessage (Handler.java:99)
        at android.os.Looper.loop (Looper.java:189)
        at android.app.ActivityThread.main (ActivityThread.java:5529)
        at java.lang.reflect.Method.invoke (Native Method)
        at java.lang.reflect.Method.invoke (Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:950)
        at com.android.internal.os.ZygoteInit.main (ZygoteInit.java: 745)

An error message appears with .

on MainActivity's 32,88,118 I think the error is that you are referring to an object that is Null, but
I don't know how to resolve it.

android java nullpointerexception

2022-09-30 19:50

1 Answers

In order to avoid NPE, at least you should add a Null check.
There is a method called TextureView.html#isAvailable(), so you should add it before mTextureView.getSurfaceTexture();.

 if(!mTextureView.isAvailable()){
    return;// TODO Implement correct exception handling
}


2022-09-30 19:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.