Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
9.1k views
in Technique[技术] by (71.8m points)

android - SpannableStringBuilder: indexOutOfBoundsException setSpan ends beyond length 0

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.IndexOutOfBoundsException: setSpan (4 ... 4) ends beyond length 0
android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:943)
android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:522)
android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:514)
android.text.Selection.setSelection(Selection.java:74)
android.text.Selection.setSelection(Selection.java:85)
android.text.method.ArrowKeyMovementMethod.onTouchEvent(ArrowKeyMovementMethod.java:410)
android.widget.TextView.onTouchEvent(TextView.java:6715)
android.widget.EditText.onTouchEvent(EditText.java:190)
android.view.View.dispatchTouchEvent(View.java:3766)
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1731)
com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1120)
android.app.Activity.dispatchTouchEvent(Activity.java:2086)
com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1715)
android.view.ViewRoot.handleMessage(ViewRoot.java:1787)
android.os.Handler.dispatchMessage(Handler.java:99)

please help me to find out the cause of this problem. Thank you in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.6k users

...