Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sometimes I get a NullPointerException and the app crashes #123

Open
andreagobetti opened this issue Oct 21, 2017 · 3 comments
Open

Sometimes I get a NullPointerException and the app crashes #123

andreagobetti opened this issue Oct 21, 2017 · 3 comments

Comments

@andreagobetti
Copy link

andreagobetti commented Oct 21, 2017

I got this error using this plugin (v 1.3.2) in an Apache Cordova app, running on a Asus ZenFone 2 Laser (ZE500KL) with Android 6.0

java.lang.NullPointerException: at org.cloudsky.cordovaPlugins.ZBarScannerActivity.onConfigurationChanged (ZBarScannerActivity.java:329) at android.app.ActivityThread.performConfigurationChanged (ActivityThread.java:4192) at android.app.ActivityThread.handleActivityConfigurationChanged (ActivityThread.java:4311) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1477) at android.os.Handler.dispatchMessage (Handler.java:102) at android.os.Looper.loop (Looper.java:148) at android.app.ActivityThread.main (ActivityThread.java:5451) at java.lang.reflect.Method.invoke (Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616)

@andreagobetti
Copy link
Author

I checked the file ZBarScannerActivity.java at line 329, which contains this code: camera.setDisplayOrientation(rotation);
so I think this issue is related with #95

@andreagobetti
Copy link
Author

Today I've registered a new, more detailed, crash:

Exception java.lang.NullPointerException: Attempt to invoke virtual method 'void android.hardware.Camera.setDisplayOrientation(int)' on a null object reference
org.cloudsky.cordovaPlugins.ZBarScannerActivity.setCameraDisplayOrientation (ZBarScannerActivity.java:247) org.cloudsky.cordovaPlugins.ZBarScannerActivity.tryStartPreview (ZBarScannerActivity.java:525) org.cloudsky.cordovaPlugins.ZBarScannerActivity.surfaceChanged (ZBarScannerActivity.java:301) android.view.SurfaceView.updateWindow (SurfaceView.java:608) android.view.SurfaceView.setFrame (SurfaceView.java:315) android.view.View.layout (View.java:16648) android.widget.FrameLayout.layoutChildren (FrameLayout.java:336) android.widget.FrameLayout.onLayout (FrameLayout.java:273) android.view.View.layout (View.java:16652) android.view.ViewGroup.layout (ViewGroup.java:5438) android.widget.FrameLayout.layoutChildren (FrameLayout.java:336) android.widget.FrameLayout.onLayout (FrameLayout.java:273) android.view.View.layout (View.java:16652) android.view.ViewGroup.layout (ViewGroup.java:5438) android.widget.LinearLayout.setChildFrame (LinearLayout.java:1743) android.widget.LinearLayout.layoutVertical (LinearLayout.java:1586) android.widget.LinearLayout.onLayout (LinearLayout.java:1495) android.view.View.layout (View.java:16652) android.view.ViewGroup.layout (ViewGroup.java:5438) android.widget.FrameLayout.layoutChildren (FrameLayout.java:336) android.widget.FrameLayout.onLayout (FrameLayout.java:273) com.android.internal.policy.PhoneWindow$DecorView.onLayout (PhoneWindow.java:2678) android.view.View.layout (View.java:16652) android.view.ViewGroup.layout (ViewGroup.java:5438) android.view.ViewRootImpl.performLayout (ViewRootImpl.java:2176) android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:1936) android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1112) android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:6035) android.view.Choreographer$CallbackRecord.run (Choreographer.java:858) android.view.Choreographer.doCallbacks (Choreographer.java:670) android.view.Choreographer.doFrame (Choreographer.java:606) android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:844) android.os.Handler.handleCallback (Handler.java:739) android.os.Handler.dispatchMessage (Handler.java:95) android.os.Looper.loop (Looper.java:148) android.app.ActivityThread.main (ActivityThread.java:5451) java.lang.reflect.Method.invoke (Method.java) com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:726) com.android.internal.os.ZygoteInit.main (ZygoteInit.java:616)

Free VM: 3.74MB
Total VM: 21.79MB
Max VM: 128MB
Battery level: 92%
Charge state: Non in charge
Connection state: Wwan

Device Model: ASUS_Z00ED
Motherboard: Msm8916
Android API: 23
Android OS: 6.0.1
RAM: 1.85GB
Device orientation: Landscape

@phongphan
Copy link

I have encountered this. Sometimes surfaceChanged is called before onResume.
This happened after onPause is called (the camera has been released), hence NPE

The #125 should address this. The camera will resume only when onResume is called. Not sure if it's affected UX though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants