SpannableStringBuilder: indexOutOfBoundsException setSpan ends beyond length 0

后端 未结 4 2017
夕颜
夕颜 2021-01-11 22:40

I am working in android. i have a problem. my application crashes when i click on my text box second time.

this is my Logcat message:

java.lang.Index         


        
4条回答
  •  余生分开走
    2021-01-11 23:14

    the cause of your problem is the following error: java.lang.IndexOutOfBoundsException: setSpan (4 ... 4) ends beyond length 0

    Apparently you're setting a span on something, but the textfield is empty, giving an IndexOutOfBoundsException, check the length of the input string before you make a call to setSpan.

    EDIT:

    Just a short clarification, an IndexOutOfBoundsException always means you're trying to access part of an array that is beyond the actual length of the array. String objects are defined as arrays of characters. As such when you're trying to do something but the length of the string is equal to zero, you actually end up beyond the boundary of an array.

提交回复
热议问题