ravi8x / Barcode-Reader

Android barcode reader using google vision library
BSD 3-Clause "New" or "Revised" License
294 stars 183 forks source link

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Thread$State java.lang.Thread.getState()' on a null object reference #40

Open azzaxx opened 4 years ago

azzaxx commented 4 years ago

Hi. With new version of gradle build tools got this exception 'com.android.tools.build:gradle:4.1.0'

E/UncaughtException: java.lang.RuntimeException: Unable to destroy activity {view.activity.ActivityBarcodeReader}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Thread$State java.lang.Thread.getState()' on a null object reference at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:5111) at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:5140) at android.app.servertransaction.DestroyActivityItem.execute(DestroyActivityItem.java:44) at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:176) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7656) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Thread$State java.lang.Thread.getState()' on a null object reference at info.androidhive.barcode.camera.CameraSource$FrameProcessingRunnable.release(CameraSource.java:1102) at info.androidhive.barcode.camera.CameraSource.release(CameraSource.java:327) at info.androidhive.barcode.camera.CameraSourcePreview.release(CameraSourcePreview.java:83) at info.androidhive.barcode.BarcodeReader.onDestroy(BarcodeReader.java:303) at androidx.fragment.app.Fragment.performDestroy(Fragment.java:2830) at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1028) at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238) at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1303) at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManagerImpl.java:2659) at androidx.fragment.app.FragmentManagerImpl.dispatchDestroy(FragmentManagerImpl.java:2644) at androidx.fragment.app.FragmentController.dispatchDestroy(FragmentController.java:329) at androidx.fragment.app.FragmentActivity.onDestroy(FragmentActivity.java:366) at androidx.appcompat.app.AppCompatActivity.onDestroy(AppCompatActivity.java:242) at view.activity.ActivityBase.onDestroy(ActivityBase.kt:162)

nanometer34688 commented 4 years ago

@azzaxx Have you managed to fix this issue?

Adnan-addi commented 3 years ago

having same issue in on destroy activity , any fix would help thank you

Tahaelhosseny commented 3 years ago

if anyone solves it please write your solution

KushalMehta1995 commented 3 years ago

have anyone solved it? please write your solution

muhammad-farhan-bakht commented 3 years ago

Hey guys I hope everyone is doing great.

Recently I have also faced this Bug and solved it. I have made the Pull Request for this bug.

In the meantime, if you want to fix it temporarily till @ravi8x merges the PR you can do the following.

  1. Download or Cloned the Library.
  2. Import this Library as a module in your Project.
  3. When completing steps 1 & 2 now go to CameraSource.java class.
  4. Remove this line assert (mProcessingThread.getState() == State.TERMINATED);

It will fix the bug.

Solution

Thanks!

Brayan1863 commented 3 years ago

I recently solved this error by uploading the same repository and making the adjustment since it has not received updates for a while, you just change the name of the package and that's it

https://github.com/Brayan1863/Barcode-Reader

SagarMaher2 commented 3 years ago

I recently solved this error by uploading the same repository and making the adjustment since it has not received updates for a while, you just change the name of the package and that's it

https://github.com/Brayan1863/Barcode-Reader

This resolve my app crash issue.

vikas0 commented 1 year ago

why was the line - assert (mProcessingThread.getState() == Thread.State.TERMINATED); was there in the first place.

I first added a null check for mProcessingThread before the line, it fixed the crash, later i realised this line was not at all needed. As before release method is called =, stop() was already callled and mProcessingThread is actually set null.