错误java.lang.IndexOutOfBoundsException:setSpan(5 ... 5)结束于长度0

时间:2019-04-24 01:38:39

标签: android

我正在使用Android Studio开发我的Andriod应用,我必须让用户将文本插入最大长度的EditText中。为此,我使用了一个lengthFilter传递给它最大长度。 错误StackInfo:

    at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1100)
    at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:675)
    at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:668)
    at android.text.Selection.setSelection(Selection.java:76)
    at android.text.Selection.setSelection(Selection.java:87)
    at android.widget.EditText.setSelection(EditText.java:98)
    at com.newlai.test.libs.utils.TextChangedListener.onTextChanged(Unknown Source)
    at android.widget.TextView.sendOnTextChanged(TextView.java:8206)
    at android.widget.TextView.handleTextChanged(TextView.java:8268)
    at android.widget.TextView$ChangeWatcher.onTextChanged(TextView.java:10435)
    at android.text.SpannableStringBuilder.sendTextChanged(SpannableStringBuilder.java:1043)
    at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:569)
    at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:492)
    at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:34)
    at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:690)
    at android.view.inputmethod.BaseInputConnection.commitText(BaseInputConnection.java:197)
    at com.android.internal.widget.EditableInputConnection.commitText(EditableInputConnection.java:184)
    at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:295)
    at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:82)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:150)
    at com.wanjian.cockroach.a.g(Unknown Source)
    at com.wanjian.cockroach.a.c(Unknown Source)
    at com.wanjian.cockroach.a$1.uncaughtException(Unknown Source)
    at com.tencent.bugly.crashreport.crash.e.a(Unknown Source)
    at com.tencent.bugly.crashreport.crash.e.uncaughtException(Unknown Source)
    at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
    at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)

这是代码

editText1.addTextChangedListener(new TextChangedListener() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                text2.setText(getString(R.string.problem_desc_num, s.length()));
            }
        });

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

我认为您应该检查代码

com.newlai.test.libs.utils.y $ 1.onTextChanged

editText1是自定义组件吗?