Reputation: 859
I have a crash report indicating an IndexOutOfBoundsException
but I have no idea what caused it since there isn't anything from my code in the stack. This is the stack:
Fatal Exception: java.lang.IndexOutOfBoundsException: setSpan (34 ... 48) ends beyond length 34
at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1265)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:684)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:677)
at android.widget.Editor$SuggestionsPopupWindow.updateSuggestions(Editor.java:3980)
at android.widget.Editor$SuggestionsPopupWindow.show(Editor.java:3833)
at android.widget.Editor.replace(Editor.java:435)
at android.widget.Editor$3.run(Editor.java:2359)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
The only thing I've found similar to my problem is this but the guy wasn't able to solve it.
How can I know what caused it so I can look for a solution?
EDIT
Ok so I found in multiple parts of my large code this function being used:
public static Spannable spannabletext(String message, int start, int end, String font_family, Typeface font) {
Spannable spannable = new SpannableString(Html.fromHtml(message));
spannable.setSpan(new CustomTypefaceSpan(font_family, font),
start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
return spannable;
}
So I'm guessing at some point this is where the problem comes from. But since I don't want to spend hours and hours trying to guess which text and in what language (my app is in 8 different languages) was this crash generated I'm going to wait till it happens again but this time I added some Crashlytics
lines so I can get more info from the crash report. So my spannabletext
function is like this now:
public static Spannable spannabletext(String message, int start, int end, String font_family, Typeface font, Activity activity) {
Crashlytics.setString("activity", activity.getLocalClassName());
Crashlytics.setString("message", message);
Crashlytics.setInt("start", start);
Crashlytics.setInt("end", end);
Spannable spannable = new SpannableString(Html.fromHtml(message));
spannable.setSpan(new CustomTypefaceSpan(font_family, font),
start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
return spannable;
}
I'll keep you posted..
Upvotes: 5
Views: 4042
Reputation: 43412
I am able to reproduce this crash with exactly the same stacktrace on my device. Can confirm it's really a framework issue and doesn't depend on your code. I can reproduce it in any app on my device including system apps like Messages, etc.
So what can we do:
Upvotes: 0
Reputation: 295
The error is not caused by your code. See the stack: at android.widget.Editor$SuggestionsPopupWindow.updateSuggestions(Editor.java:3980)
that occurred when long-clicking the text to show the PopWindow. So it's a framework error, not yours.
This answer is better: EditText crashing on clearing text
Problem is "updateSuggestions" try to setSpan after you change text in EditText. So you need make text change after editor modify EditText. Just put your code in view.post
mEditText.post {
mEditText.setText("your text")
}
Upvotes: 1