zxing-android-embedded icon indicating copy to clipboard operation
zxing-android-embedded copied to clipboard

IllegalStateException: CameraInstance is not open

Open ekahannah opened this issue 8 years ago • 20 comments

Description of the problem:

Encountered a crash on using your library. Crash log is as follows: IllegalStateException: CameraInstance is not open Module "com.journeyapps.barcodescanner.v", line 38, in handleMessage Module "com.journeyapps.barcodescanner.u", line 22, in a Module "com.journeyapps.barcodescanner.u", line 162, in b Module "com.journeyapps.barcodescanner.u", line 118, in c Module "com.journeyapps.barcodescanner.a.e", line 143, in a

Apologies as our code is obfuscated but the app occured on your library

Which library version are you using? E.g. 3.2.0. 3.1.0

Which phone/tablet are you using, and which Android version does it run? (e.g. Samsung Galaxy S5, Android 5.0)

Does the same happen on other devices or an emulator?

Can you reproduce the issue in the sample project included with the library? If not, can you provide your own sample project or sample code that produces this error?

In the case of an error do you have a stack trace or adb logs? Encountered a crash on using your library. Crash log is as follows: IllegalStateException: CameraInstance is not open Module "com.journeyapps.barcodescanner.v", line 38, in handleMessage Module "com.journeyapps.barcodescanner.u", line 22, in a Module "com.journeyapps.barcodescanner.u", line 162, in b Module "com.journeyapps.barcodescanner.u", line 118, in c Module "com.journeyapps.barcodescanner.a.e", line 143, in a

ekahannah avatar Jan 26 '17 06:01 ekahannah

  1. Did you add the camera permission on your Android manifest?

  2. Does that error occurs when you try to use the scanner for the 1st time?

renatosc avatar Jan 26 '17 08:01 renatosc

Hi, Thanks for your response. Comments are found below:

  1. Yes, I did add the camera permission on my Android Manifest.

  2. So far the crash only happened once. I got the crash from a crash tool (https://sentry.io).

May I know what are the possible ways on why the "IllegalStateException: CameraInstance is not open" is triggered?

ekahannah avatar Jan 26 '17 08:01 ekahannah

That error is when the app was not able to open the Camera. It can happens for several reasons like the app didn't request camera permission, or the camera is already opened by the same/other app,..

I was happening that problem once when tried to show the scanner for the 2nd time and then I noticed that although I was removing the camera preview from the screen, I was not closing it, so when I tried to show the scanner again, it failed to open.

Are you using any of the samples or the IntentIntegrator?

renatosc avatar Jan 26 '17 11:01 renatosc

Sorry for the late reply.

I tried to manually disable camera permission on Marshmallow device but the error didn't happen.

I am using the Embedded BarcodeView.

ekahannah avatar Feb 01 '17 02:02 ekahannah

@ekahannah When this happens, there is typically also another error a few lines earlier with more details on why the camera could not be opened (e.g. camera already in use).

A non-obfuscated stack trace will also help.

rkistner avatar Mar 20 '17 11:03 rkistner

Hi, I experienced the same issue, here the stack trace and some info

Exception java.lang.IllegalStateException: CameraInstance is not open com.journeyapps.barcodescanner.camera.CameraInstance.validateOpen (CameraInstance.java) com.journeyapps.barcodescanner.camera.CameraInstance.setDisplayConfiguration (CameraInstance.java) <OR>.getDisplayConfiguration (CameraInstance.java) <OR>.setReadyHandler (CameraInstance.java) <OR>.setSurface (CameraInstance.java) <OR>.setCameraSettings (CameraInstance.java) <OR>.setTorch (CameraInstance.java) <OR>.requestPreview (CameraInstance.java) <OR>.notifyError (CameraInstance.java) <OR>.access$000 (CameraInstance.java) <OR>.access$200 (CameraInstance.java) <OR>.access$602 (CameraInstance.java) com.journeyapps.barcodescanner.DecoderThread.requestNextPreview (DecoderThread.java) <OR>.access$300 (DecoderThread.java) com.journeyapps.barcodescanner.DecoderThread.stop (DecoderThread.java) <OR>.decode (DecoderThread.java) <OR>.access$200 (DecoderThread.java) com.journeyapps.barcodescanner.DecoderThread.setDecoder (DecoderThread.java) <OR>.setCropRect (DecoderThread.java) <OR>.start (DecoderThread.java) <OR>.createSource (DecoderThread.java) <OR>.access$000 (DecoderThread.java) <OR>.access$100 (DecoderThread.java) com.journeyapps.barcodescanner.DecoderThread$1.handleMessage (DecoderThread.java) android.os.Handler.dispatchMessage (Handler.java:98) android.os.Looper.loop (Looper.java:158) android.os.HandlerThread.run (HandlerThread.java:61)

User Country Code: — Carrier Code: — Carrier: vodafone IT Locale: it-IT

Performance VM free: 13.55MB VM total: 57.1MB VM max: 128MB Battery level: 55% Charging state: Unplugged Connection State: Wwan

Device Manufacturer: Samsung Model: SM-G903F Board: Universal7580 Android API: 23 Android OS: 6.0.1 Brand: Samsung RAM: 1.81GB Orientation: Portrait Proximity to user: —

Error Date: Jul 25, 2017, 2:15:19 PM App Version: 10005 (1.0.5)

GiovanniM avatar Jul 27 '17 07:07 GiovanniM

Sorry, when you see only .METHOD_NAME instead of the full class path there is an OR, firebase gave me the stacktrace as I pasted

GiovanniM avatar Jul 27 '17 07:07 GiovanniM

hi @rkistner,

Faced with similar problem and do have stacktrace of all threads, captured by fabric - IllegalStateException_CameraInstance_is_not_open.txt . Please, take a look, and hope it helps to fix the crash.

andrii-borysov-me avatar Jul 27 '17 17:07 andrii-borysov-me

I experienced the same issue ,

com.journeyapps.barcodescanner.camera.CameraInstance.validateOpen(CameraInstance.java:181)

2 com.journeyapps.barcodescanner.camera.CameraInstance.requestPreview(CameraInstance.java:169) 3 com.journeyapps.barcodescanner.DecoderThread.requestNextPreview(DecoderThread.java:129) 4 com.journeyapps.barcodescanner.DecoderThread.decode(DecoderThread.java:173) 5 com.journeyapps.barcodescanner.DecoderThread.access$000(DecoderThread.java:22) 6 com.journeyapps.barcodescanner.DecoderThread$1.handleMessage(DecoderThread.java:38) 7 android.os.Handler.dispatchMessage(Handler.java:98) 8 android.os.Looper.loop(Looper.java:136) 9 android.os.HandlerThread.run(HandlerThread.java:61)

BigKarel avatar Aug 11 '17 00:08 BigKarel

I've seen the same crash here in some of my users' reports. Looking at the code, it seems to me as if the culprit is in the CameraInstance.close method. What I think is happening is that the closer runnable runs before the open variable is set to false, and at the same time the decoder thread is trying to decode the next frame - in requestNextPreview. There is a cameraInstance.isOpen call in there, but what if the open variable hasn't been set yet in the close method, but when it reaches the validateOpen method of requestPreview in CameraInstance it has? This is all possible because of the threading. One easy solution would be to set the open variable to false before enqueueing the closer runnable.

Speaking of which, shouldn't the open variable be synchronized? Since it's both read and written to from different threads.

HomerSp avatar Sep 05 '17 09:09 HomerSp

@rkistner

Facing the same issue.

I was wondering as to why do we have to crash in this scenario?

yashasvigirdhar avatar Oct 13 '17 08:10 yashasvigirdhar

Samsung Grand Prime Plus (grandpplte), 1536MB RAM, Android 6.0 Informe 1 java.lang.IllegalStateException:

at com.journeyapps.barcodescanner.camera.CameraInstance.validateOpen (CameraInstance.java:181) at com.journeyapps.barcodescanner.camera.CameraInstance.requestPreview (CameraInstance.java:169) at com.journeyapps.barcodescanner.DecoderThread.requestNextPreview (DecoderThread.java:129) at com.journeyapps.barcodescanner.DecoderThread.decode (DecoderThread.java:173) at com.journeyapps.barcodescanner.DecoderThread.access$000 (DecoderThread.java:22) at com.journeyapps.barcodescanner.DecoderThread$1.handleMessage (DecoderThread.java:38) at android.os.Handler.dispatchMessage (Handler.java:98) at android.os.Looper.loop (Looper.java:148) at android.os.HandlerThread.run (HandlerThread.java:61)

oduconge avatar Nov 20 '17 04:11 oduconge

Hey I also had this issue on Huawei P9 running Android 7.0.

Fatal Exception: java.lang.IllegalStateException CameraInstance is not open

com.journeyapps.barcodescanner.camera.CameraInstance.validateOpen (CameraInstance.java:181)
com.journeyapps.barcodescanner.camera.CameraInstance.requestPreview (CameraInstance.java:169)
com.journeyapps.barcodescanner.DecoderThread.requestNextPreview (DecoderThread.java:129)
com.journeyapps.barcodescanner.DecoderThread.decode (DecoderThread.java:173)
com.journeyapps.barcodescanner.DecoderThread.access$000 (DecoderThread.java:22)
com.journeyapps.barcodescanner.DecoderThread$1.handleMessage (DecoderThread.java:38)
android.os.Handler.dispatchMessage (Handler.java:101)
android.os.Looper.loop (Looper.java:156)
android.os.HandlerThread.run (HandlerThread.java:61)

mzgreen avatar Dec 09 '17 17:12 mzgreen

I also had this issue on iBall running Android 5.1 Fatal Exception: java.lang.IllegalStateException: CameraInstance is not open at com.journeyapps.barcodescanner.camera.CameraInstance.validateOpen(CameraInstance.java:181) at com.journeyapps.barcodescanner.camera.CameraInstance.requestPreview(CameraInstance.java:169) at com.journeyapps.barcodescanner.DecoderThread.requestNextPreview(DecoderThread.java:129) at com.journeyapps.barcodescanner.DecoderThread.decode(DecoderThread.java:1173) at com.journeyapps.barcodescanner.DecoderThread$1.handleMessage(DecoderThread.java:38) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:194) at android.os.HandlerThread.run(HandlerThread.java:61)

Please suggest a way to resolve this issue. Thank You!!

abhisshek avatar Aug 27 '18 08:08 abhisshek

@rkistner here is a a non-obfuscated stack trace, which is also similar to some users who commented above:

java.lang.IllegalStateException: CameraInstance is not open at com.journeyapps.barcodescanner.camera.CameraInstance.validateOpen(CameraInstance.java:181) at com.journeyapps.barcodescanner.camera.CameraInstance.requestPreview(CameraInstance.java:169) at com.journeyapps.barcodescanner.DecoderThread.requestNextPreview(DecoderThread.java:129) at com.journeyapps.barcodescanner.DecoderThread.decode(DecoderThread.java:173) at com.journeyapps.barcodescanner.DecoderThread.access$000(DecoderThread.java:22) at com.journeyapps.barcodescanner.DecoderThread$1.handleMessage(DecoderThread.java:38) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:154) at android.os.HandlerThread.run(HandlerThread.java:61)

pnevalle avatar Sep 12 '18 10:09 pnevalle

Faced a similar problem. Maybe someone already found a solution to this problem?

Device: HUAWEI P8 Lite, Android 6.0 Stack Tracing: Fatal Exception: java.lang.IllegalStateException: CameraInstance is not open at com.journeyapps.barcodescanner.camera.CameraInstance.validateOpen(CameraInstance.java:155) at com.journeyapps.barcodescanner.camera.CameraInstance.requestPreview(CameraInstance.java:143) at com.journeyapps.barcodescanner.DecoderThread.requestNextPreview(DecoderThread.java:118) at com.journeyapps.barcodescanner.DecoderThread.decode(DecoderThread.java:162) at com.journeyapps.barcodescanner.DecoderThread.access$000(DecoderThread.java:22) at com.journeyapps.barcodescanner.DecoderThread$1.handleMessage(DecoderThread.java:38) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:150) at android.os.HandlerThread.run(HandlerThread.java:61)

antileks avatar Nov 07 '19 03:11 antileks

@antileks Which version of the library are you using?

rkistner avatar Nov 07 '19 08:11 rkistner

@antileks Which version of the library are you using?

I use this: implementation 'com.journeyapps:zxing-android-embedded:3.2.0@aar'

antileks avatar Nov 07 '19 11:11 antileks

I recommend upgrading to the latest version in that case - quite a few fixes has been made since then, which may affect this issues as well.

rkistner avatar Nov 07 '19 11:11 rkistner

@rkistner Thank you!

antileks avatar Nov 07 '19 12:11 antileks