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

IllegalStateException: CameraInstance is not open #272

Open
ekahannah opened this issue Jan 26, 2017 · 20 comments
Open

IllegalStateException: CameraInstance is not open #272

ekahannah opened this issue Jan 26, 2017 · 20 comments
Labels

Comments

@ekahannah
Copy link

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

@renatosc
Copy link

  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?

@ekahannah
Copy link
Author

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?

@renatosc
Copy link

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?

@ekahannah
Copy link
Author

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.

@rkistner
Copy link
Member

@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.

@GiovanniM
Copy link

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)
.getDisplayConfiguration (CameraInstance.java)
.setReadyHandler (CameraInstance.java)
.setSurface (CameraInstance.java)
.setCameraSettings (CameraInstance.java)
.setTorch (CameraInstance.java)
.requestPreview (CameraInstance.java)
.notifyError (CameraInstance.java)
.access$000 (CameraInstance.java)
.access$200 (CameraInstance.java)
.access$602 (CameraInstance.java)
com.journeyapps.barcodescanner.DecoderThread.requestNextPreview (DecoderThread.java)
.access$300 (DecoderThread.java)
com.journeyapps.barcodescanner.DecoderThread.stop (DecoderThread.java)
.decode (DecoderThread.java)
.access$200 (DecoderThread.java)
com.journeyapps.barcodescanner.DecoderThread.setDecoder (DecoderThread.java)
.setCropRect (DecoderThread.java)
.start (DecoderThread.java)
.createSource (DecoderThread.java)
.access$000 (DecoderThread.java)
.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
Copy link

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

@andrii-borysov-me
Copy link

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.

@BigKarel
Copy link

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)

@HomerSp
Copy link
Contributor

HomerSp commented Sep 5, 2017

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.

@yashasvigirdhar
Copy link

@rkistner

Facing the same issue.

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

@oduconge
Copy link

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)

@mzgreen
Copy link

mzgreen commented Dec 9, 2017

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)

@abhisshek
Copy link

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!!

@pnevalle
Copy link

@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)

@antileks
Copy link

antileks commented Nov 7, 2019

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)

@rkistner
Copy link
Member

rkistner commented Nov 7, 2019

@antileks Which version of the library are you using?

@antileks
Copy link

antileks commented Nov 7, 2019

@antileks Which version of the library are you using?

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

@rkistner
Copy link
Member

rkistner commented Nov 7, 2019

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.

@antileks
Copy link

antileks commented Nov 7, 2019

@rkistner Thank you!

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

No branches or pull requests