google / cameraview

[DEPRECATED] Easily integrate Camera features into your Android app
Apache License 2.0
4.74k stars 1.03k forks source link

java.lang.NullPointerException on samsung SM-G9550 #257

Open Lans opened 5 years ago

Lans commented 5 years ago

java.lang.NullPointerException: Attempt to invoke virtual method 'int android.hardware.camera2.CameraCaptureSession.capture(android.hardware.camera2.CaptureRequest, android.hardware.camera2.CameraCaptureSession$CaptureCallback, android.os.Handler)' on a null object reference at com.google.android.cameraview.Camera2.unlockFocus(TbsSdkJava:662) at com.google.android.cameraview.Camera2$6.onCaptureCompleted(TbsSdkJava:646) at java.lang.reflect.Method.invoke(Native Method) at android.hardware.camera2.dispatch.InvokeDispatcher.dispatch(InvokeDispatcher.java) at android.hardware.camera2.dispatch.HandlerDispatcher$1.run(HandlerDispatcher.java) at android.os.Handler.handleCallback(Handler.java) at android.os.Handler.dispatchMessage(Handler.java) at android.os.Looper.loop(Looper.java) at android.app.ActivityThread.main(ActivityThread.java) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)

kraa commented 5 years ago

Same on Samsung Galaxy A8 SM-A530F

It happens because CameraView stop called earlier then unlockFocus

Lans commented 5 years ago

Same on Samsung Galaxy A8 SM-A530F

It happens because CameraView stop called earlier then unlockFocus

how to solve it

kraa commented 5 years ago

I don't look for reason of that.. You need to delay cameraview stop. The straight-forward solution is simply call stop (that you do after cameraview captured image) with delay like new Handler().postDelayed(() -> cameraView.stop(), 200);

It's fast but ugly solution.

Lans commented 5 years ago

I don't look for reason of that.. You need to delay cameraview stop. The straight-forward solution is simply call stop (that you do after cameraview captured image) with delay like new Handler().postDelayed(() -> cameraView.stop(), 200);

It's fast but ugly solution.

I don't look for reason of that.. You need to delay cameraview stop. The straight-forward solution is simply call stop (that you do after cameraview captured image) with delay like new Handler().postDelayed(() -> cameraView.stop(), 200);

It's fast but ugly solution.

After samsung's camera is called, the system will call ondestroy and the activity will be destroyed and rebuilt, because the system calls a horizontal and vertical switch

<activity
        android:name=".activity.CameraActivity"
        android:configChanges="orientation|keyboardHidden"
        android:launchMode="singleTop"
        android:screenOrientation="portrait"
        android:theme="@style/AppThemeNoBackground" />

You can try this

jjn2004 commented 5 years ago

anyone has the final solution? we meet it on HUAWEI 8.0.0 phone