Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpannableStringBuilder: indexOutOfBoundsException setSpan ends beyond length 0

Tags:

android

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.

like image 1000
R Fauzdar Avatar asked Dec 22 '11 09:12

R Fauzdar


1 Answers

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.

like image 100
SegF4ult Avatar answered Sep 21 '22 09:09

SegF4ult