SubhamTyagi / android-ocr

Tesseract based OCR for android
Apache License 2.0
355 stars 61 forks source link

app crashes when selecting multiple languages #107

Open TalOrenshtein opened 10 months ago

TalOrenshtein commented 10 months ago

Steps to reproduce:

  1. Go to settings
  2. Enable the multiple languages toggle
  3. Select 2 or more languages.

As soon as I confirm the languages, the app crash and refuse to open. Log:

java.lang.RuntimeException: Unable to resume activity {io.github.subhamtyagi.ocr/io.github.subhamtyagi.ocr.MainActivity}: java.lang.ArrayIndexOutOfBoundsException: length=130; index=-1
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4774)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:4807)
    at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:57)
    at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
    at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:179)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:201)
    at android.os.Looper.loop(Looper.java:288)
    at android.app.ActivityThread.main(ActivityThread.java:7924)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=130; index=-1
    at java.util.ArrayList.get(ArrayList.java:439)
    at io.github.subhamtyagi.ocr.MainActivity.t(Unknown Source:8)
    at io.github.subhamtyagi.ocr.MainActivity.onResume(Unknown Source:7)
    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1570)
    at android.app.Activity.performResume(Activity.java:8474)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:4764)
    ... 13 more
muchuelo commented 9 months ago

I have exactly the same problem, except the app does not crash immediately after adding extra languages to the list. But it crashes every time I try to start it if multiple languages are selected.

Uninstalled and reinstalled several times to confirm that selection of multiple languages causes the crash.

After a clean install, the app chooses the default language itself, then successfully downloads the training data, and successfully OCR's an image of text, but once you go into the settings and change anything (add multiple languages, or even just change Tesseract quality from Fast to Best) the app does not download training data for selected languages, and once closed, will always crash when trying to start the app again.

wincentbalin commented 9 months ago

Pull request #89 should fix the problem.

j-lakeman commented 8 months ago

@SubhamTyagi any updates on this?

hubortje commented 4 months ago

The issue persists with 4.0 (F-Droid) on GrapheneOS.

type: crash
osVersion: google/husky/husky:14/UQ1A.240205.004/2024022800:user/release-keys
package: io.github.subhamtyagi.ocr:12
process: io.github.subhamtyagi.ocr
processUptime: 80 + 204 ms
installer: org.fdroid.fdroid

java.lang.RuntimeException: Unable to start activity ComponentInfo{io.github.subhamtyagi.ocr/io.github.subhamtyagi.ocr.MainActivity}: java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 130
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3833)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3974)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:139)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:96)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2475)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loopOnce(Looper.java:205)
    at android.os.Looper.loop(Looper.java:294)
    at android.app.ActivityThread.main(ActivityThread.java:8279)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
    at com.android.internal.os.ExecInit.main(ExecInit.java:49)
    at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
    at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:359)
Caused by: java.lang.IndexOutOfBoundsException: Index -1 out of bounds for length 130
    at jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
    at jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
    at jdk.internal.util.Preconditions.checkIndex(Preconditions.java:266)
    at java.util.Objects.checkIndex(Objects.java:359)
    at java.util.ArrayList.get(ArrayList.java:434)
    at io.github.subhamtyagi.ocr.MainActivity.t(Unknown Source:8)
    at io.github.subhamtyagi.ocr.MainActivity.s(SourceFile:32)
    at io.github.subhamtyagi.ocr.MainActivity.u(SourceFile:246)
    at io.github.subhamtyagi.ocr.MainActivity.onCreate(SourceFile:246)
    at android.app.Activity.performCreate(Activity.java:8674)
    at android.app.Activity.performCreate(Activity.java:8652)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1461)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3815)
    ... 14 more
Thomas-AA commented 4 months ago

Hi,

I experience the same problem. on release 11 & 12 (v4.0) from f-droid.org

Android 10 / LineageOS

deadcombo commented 4 months ago

Sign-in to GitHub, go to Actions in this repo, open the latest one and download the .apk under Artifacts. You can only download it if you're logged in.

T8RIN commented 3 months ago

You can use ImageToolbox

vishalscodes commented 2 months ago

Same problem here. Here's a recording:

https://github.com/SubhamTyagi/android-ocr/assets/104351431/c3f9233d-96ad-4f47-b5ee-484c74c1007a

EDIT: Upon testing, @deadcombo's answer works.