Android Question Google Play Console - Crash Report java.lang.IndexOutOfBoundsException: setSpan (4 ... 4) ends beyond length 2

PhilN

Member
Licensed User
Longtime User
I have submitted my app for internal testing and get this error in the crash report:

JavaScript:
FATAL EXCEPTION: main
Process: gyromagnetic.compass, PID: 19303
java.lang.IndexOutOfBoundsException: setSpan (4 ... 4) ends beyond length 2
    at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1022)
    at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:615)
    at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:611)
    at android.text.Selection.setSelection(Selection.java:76)
    at android.text.Selection.setSelection(Selection.java:87)
    at android.widget.EditText.setSelection(EditText.java:99)
    at android.widget.EditText.performAccessibilityAction(EditText.java:145)
    at android.view.AccessibilityInteractionController.perfromAccessibilityActionUiThread(AccessibilityInteractionController.java:626)
    at android.view.AccessibilityInteractionController.access$500(AccessibilityInteractionController.java:53)
    at android.view.AccessibilityInteractionController$PrivateHandler.handleMessage(AccessibilityInteractionController.java:1135)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5538)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

I have searched for an answer to resolve this problem but am at a loss as the only vague answer I could find is here but I don't know what to make of it. According to me I have taken the necessary measure to make sure that I do not exceed the EditText1.Text.Length string length. Here is the problematic code that seems to generate the error in lines 9 and 21:

Code that apparently generates the error:
Sub edtWPH_FocusChanged (HasFocus As Boolean)
    If HasFocus = False Then 'the user has moved the cursor to another edit text field (similar to enter pressed)
        Dim edt As EditText
        edt = Sender       
        If edt.Text = "" Or edt.Text > 359 Or edt.Text < 0 Then
            ToastMessageShow("Value must be from 0 to 359", True)
            edt.Text = "0"
        End If
        edt.SelectionStart = edt.Text.Length 'move cursor to end
        Main.edtWPheadings(edt.Tag) = edt.Text 'copy user entry to the WP arrays
    End If
End Sub

Sub edtWPH_EnterPressed
    Dim edt As EditText
    edt = Sender
    If edt.Text = "" Or edt.Text > 359 Or edt.Text < 0 Then
        ToastMessageShow("Value must be from 0 to 359", True)
        edt.Text = "0"
    End If
    edt.SelectionStart = edt.Text.Length 'move cursor to end
    Main.edtWPheadings(edt.Tag) = edt.Text 'copy user entry to the WP arrays
End Sub

What am I doing wrong? I have tested it on my own devices and cannot reproduce the error above. I have tried everything to try and "break" it but i can't. Please help me resolve this error. Thanks in advance, any help is much appreciated.
 

PhilN

Member
Licensed User
Longtime User
SOLVED: I opted to remove the two lines of code since they were not important in any case. The error is gone! I know that this is not the best or right way to resolve it, but it certainly worked for me.
 
Upvote 0
Top