Skip to content Skip to sidebar Skip to footer

Indexoutofboundsexception For Setspan - Outside My Application Code

I recently published an update to my Android app and have been getting a ton of crash reports, with the following stack. I'm at a loss since there's absolutely no code of mine in t

Solution 1:

i think you have white spaces in your string you have like eleven white space string but no character so actual/trimmed length is zero, this will cause error to set selection. you can check myString.trim().lenght() > 0 before setting your selection position.

Solution 2:

When suggestion is used to correct the wrong word, Editor#replaceWithSuggestion is called, and then TextView#setSpan_internal and setCursorPosition_internal are called, but maxLength is not judged here, so it crashes.

Thanks Ring. The following solved my issue. I extended EditText and override following methods,

protectedvoidsetSpan_internal(Object span, int start, int end, intflags){
        finalint textLength = getText().length();
        ((Editable) getText()).setSpan(span, start, Math.min(end, textLength), flags);
    }

protectedvoidsetCursorPosition_internal(int start, int end){
    finalint textLength = getText().length();
    Selection.setSelection(((Editable) getText()), Math.min(start, textLength), Math.min(end, textLength));
}

From: https://issuetracker.google.com/issues/36944935#comment5

Post a Comment for "Indexoutofboundsexception For Setspan - Outside My Application Code"