SubhamTyagi / android-ocr

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

Crashes when having two languages selected #67

Open rugk opened 2 years ago

rugk commented 2 years ago

STR

  1. Open app, configure.
  2. Choose to allow multiple languages in the settings.
  3. Select German and English.

what happens

At the next start/going to main screen the app crashes.

FATAL EXCEPTION: main
Process: io.github.subhamtyagi.ocr, PID: 25329
java.lang.RuntimeException: Unable to start activity ComponentInfo{io.github.subhamtyagi.ocr/io.github.subhamtyagi.ocr.MainActivity}: java.lang.ArrayIndexOutOfBoundsException: length=130; index=-1
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3707)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3864)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2253)
    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:7870)
    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:1003)
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=130; index=-1
    at java.util.ArrayList.get(ArrayList.java:439)
    at io.github.subhamtyagi.ocr.MainActivity.y(Unknown Source:8)
    at io.github.subhamtyagi.ocr.MainActivity.x(Unknown Source:31)
    at io.github.subhamtyagi.ocr.MainActivity.z(:15)
    at io.github.subhamtyagi.ocr.MainActivity.onCreate(:4)
    at android.app.Activity.performCreate(Activity.java:8057)
    at android.app.Activity.performCreate(Activity.java:8037)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1345)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3688)
    ... 12 more

what should happen

No crash.

system

Device: Pixel 4 (flame)
OS: Android 12, CalyxOS 3.6.0
source: F-Droid
version: v3.2 Build-ID: SQ3A.220605.009.A1.22306002

redtux commented 1 year ago

Thanks for reporting this, I can confirm the bug. Just wanted to report it as well, and then found this issue. 👍

As described, the app only crashes when selecting multiple languages and does not start again until deleting all data. 😿

FabulousOne commented 1 year ago

Same happened to me...

now0clock commented 1 year ago

Still an issue. Same

RedSteel-1 commented 1 year ago

The same :-/ Opened settings, chose some languages, and now impossible to launch, crashes on every attempt.

katastrophe92 commented 1 year ago

I have the loop open app-crash app still also when having multiple languages selected

wincentbalin commented 1 year ago

I confirm the crash as described above too. Also, this issue is a duplicate of the issue #40.

operarulez commented 1 year ago

That works:

private String getLanguageNameFromCode(String code) {
    if (code.contains("+")) {
        String[] lang_codes = code.split("\\+");
        StringBuilder rLanguageName = new StringBuilder();
        for (String lang : lang_codes) {
            rLanguageName.append(languagesNames.get(languagesCodes.indexOf(lang)));
            rLanguageName.append("+");
        }
        return rLanguageName.subSequence(0, rLanguageName.toString().lastIndexOf('+')).toString();
    } else {
        return languagesNames.get(languagesCodes.indexOf(code));
    }
}