Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Editor.java IndexOutOfBoundsException offset(x) should be less than line limit(y)

Hi have anyone know this crash?

Still confusing how to reproduce. From the stackTrace it is something related to Email EditText.

and majority is happen on Xiaomi's Redmi devices and 100% Android 10

Full stackTrace

Editor.java line 3324
Fatal Exception: java.lang.IndexOutOfBoundsException
offset(18) should be less than line limit(17)

    android.text.TextLine.measure (TextLine.java:353)
    android.text.Layout.getHorizontal (Layout.java:1213)
    android.text.Layout.getHorizontal (Layout.java:1190)
    android.text.Layout.getPrimaryHorizontal (Layout.java:1160)
    android.text.Layout.getPrimaryHorizontal (Layout.java:1149)
    android.widget.Editor$ActionPinnedPopupWindow.computeLocalPosition (Editor.java:3324)
    android.widget.Editor$PinnedPopupWindow.show (Editor.java:3628)
    android.widget.Editor$ActionPinnedPopupWindow.show (Editor.java:3471)
    android.widget.Editor$EmailAddPopupWindow.show (Editor.java:4995)
    android.widget.Editor$1.run (Editor.java:1528)
    android.os.Handler.handleCallback (Handler.java:914)
    android.os.Handler.dispatchMessage (Handler.java:100)
    android.os.Looper.loop (Looper.java:225)
    android.app.ActivityThread.main (ActivityThread.java:7563)
    java.lang.reflect.Method.invoke (Method.java)
    com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:539)
    com.android.internal.os.ZygoteInit.main (ZygoteInit.java:994)
like image 951
michael chen Avatar asked Dec 20 '25 08:12

michael chen


1 Answers

offset(X) should be less than line limit(Y)

I had a similar error in Android 12+ EditTexts. It happens when, for some reason, EditText.getText().length() (called Y in the error above) does not match the actual length of the copy-pasted text (called X in the error above).

Our workaround is to extend EditText and then manually call setText("", TextView.BufferType.EDITABLE) (in our case, in onTextContextMenuItem), since it appears to correct the expected text length with the actual text length.

like image 51
Siklab.ph Avatar answered Dec 22 '25 00:12

Siklab.ph



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!