title: IndexOutOfBoundsException setSpan (34 ... 48) ends beyond length 34
body: <p>I have a crash report indicating an <code>IndexOutOfBoundsException</code> but I have no idea what caused it since there isn't anything from my code in the stack. This is the stack: </p>
  
  <pre><code>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)
  </code></pre>
  
  <p>The only thing I've found similar to my problem is <a href="https://stackoverflow.com/questions/26948302/indexoutofboundsexception-for-setspan-outside-my-application-code">this</a> but the guy wasn't able to solve it.</p>
  
  <p>How can I know what caused it so I can look for a solution?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Ok so I found in multiple parts of my large code this function being used:</p>
  
  <pre><code>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;
  
  }
  </code></pre>
  
  <p>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 <code>Crashlytics</code> lines so I can get more info from the crash report. So my <code>spannabletext</code> function is like this now:</p>
  
  <pre><code>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;
  
  }
  </code></pre>
  
  <p>I'll keep you posted..</p>