Unboxing of 'characteristics.get(CameraCharacteristics.LENS_FACING) 'may produce' java.lang.NullPointerException'

Asked 2 years ago, Updated 2 years ago, 83 views

https://github.com/yabushi/TimeStampCamera

The part I wrote myself ↓
https://github.com/yabushi/TimeStampCamera/blob/4b4c441675a6a5e7d6b2cf1f0448e19b1a115fd7/app/src/main/java/com/example/shigeki/timestampcamera/MainActivity.java

When I try to run a program in , I see "Exit TimeStampCamera because there is a problem with my Android device", and I get the following error:

I thought there might be a problem with characteristics.get(CameraCharacteristics.LENS_FACING) in line 72, but I don't know how to solve it.
Thank you for your cooperation.

E/AndroidRuntime:FATAL EXCEPTION:main
    Process: com.example.shigeki.timestampcamera, PID:867
    java.lang.RuntimeException: Unable to instantiate activity ComponentInfo {com.example.shigeki.timestampcamera/com.example.shigeki.timestampcamera.MainActivity}:java.lang.NullPointerException:Attempt to invoice virtual.video.video$view
        at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2366)
        at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2517)
        at android.app.ActivityThread.access$800 (ActivityThread.java:162)
        at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1412)
        at android.os.Handler.dispatchMessage (Handler.java:106)
        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)
     Caused by: java.lang.NullPointerException: Attempt to Invoke virtual method' android.view.Window$Callback android.view.Window.getCallback()'on a null object reference
        at android.support.v7.app.AppCompatDelegateImplBase.<init> (AppCompatDelegateImplBase.java:117)
        at android.support.v7.app.AppCompatDelegateImplV9.<init> (AppCompatDelegateImplV9.java:149)
        at android.support.v7.app.AppCompatDelegateImplV14.<init> (AppCompatDelegateImplV14.java:56)
        at android.support.v7.app.AppCompatDelegate.create (AppCompatDelegate.java:202)
        at android.support.v7.app.AppCompatDelegate.create (AppCompatDelegate.java:183)
        at android.support.v7.app.AppCompatActivity.getDelegate (AppCompatActivity.java:519)
        at android.support.v7.app.AppCompatActivity.findViewById (AppCompatActivity.java:190)
        at com.example.shigeki.timestampcamera.MainActivity.<init> (MainActivity.java:46)
        at java.lang.reflect.Constructor.newInstance(Native Method)
        at java.lang.Class.newInstance (Class.java:1572)
        at android.app.instrumentation.newActivity (instrumentation.java:1065)
        at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2356)
        at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2517) 
        at android.app.ActivityThread.access$800 (ActivityThread.java:162) 
        at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1412) 
        at android.os.Handler.dispatchMessage (Handler.java:106) 
        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) 

camera nullpointerexception

2022-09-30 11:12

1 Answers

This is the original program.

public class MainActivity extends AppCompatActivity {

    // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // / fields // // // //

    Camera by a variable for instance, for example, Device /
    CameraDevice mCameraDevice;

    Cameron / Capital Ventures SessionBean1 maxTripRowSet variables
    CameraCaptureSession mCaptureSession = null;

    / / Capture Request for variable
    CaptureRequest mPreviewRequest = null;

    private CaptureRequest.Builder mPreviewRequestBuilder;

        Texas ’ view set on a screen / View
        final TextureView mTextureView = findViewById(R.id.textureview);

        When a shutter button /
        final Button ShutterButton = findViewById(R.id.shutter);


    //////////////////////////////////////////////////////////////////////////////////////////

    @SuppressLint("MissingPermission")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

Changing the definition location of mTextureView and ShutterButton as shown below resolved the issue.

public class MainActivity extends AppCompatActivity {

    // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // / fields // // // //

    Camera by a variable for instance, for example, Device /
    CameraDevice mCameraDevice;

    Cameron / Capital Ventures SessionBean1 maxTripRowSet variables
    CameraCaptureSession mCaptureSession = null;

    / / Capture Request for variable
    CaptureRequest mPreviewRequest = null;

    private CaptureRequest.Builder mPreviewRequestBuilder;


    //////////////////////////////////////////////////////////////////////////////////////////

    @SuppressLint("MissingPermission")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Texas ’ view set on a screen / View
        final TextureView mTextureView = findViewById(R.id.textureview);

        When a shutter button /
        final Button ShutterButton = findViewById(R.id.shutter);


2022-09-30 11:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.