java.lang.IndexOutOfBoundsException:setSpan(N ... N)结束于长度10500 [英] java.lang.IndexOutOfBoundsException: setSpan (N ... N) ends beyond length 10500

查看:968
本文介绍了java.lang.IndexOutOfBoundsException:setSpan(N ... N)结束于长度10500的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我致电EditText.setSelection()

java.lang.IndexOutOfBoundsException: setSpan (N ... N) ends beyond length 10500

N可以是任何数字.例如,如果我呼叫setSelection(10476,10568),N将为10568.但是10500是恒定的.

N can be any number. For example if I call setSelection(10476,10568) N will be 10568. But 10500 is constant.

          java.lang.IndexOutOfBoundsException: setSpan (10568 ... 10568) ends beyond length 10500
              at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1090)
              at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:665)
              at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:658)
              at android.text.Selection.setSelection(Selection.java:78)
              at android.widget.EditText.setSelection(EditText.java:91)
...

EditText是否存在引起这种情况的任何限制?

Are there any limitations of EditText that cause this?

在进行选择之前,我加载了一个文本文件,该文件肯定包含10500多个字符,因为它包含ca. 12000行.然后,我调用EditText.setText()将文件内容放入字段中. EditText.setText()可以正常工作. 首先,我觉得有一些错误的文件内容,但我装的另一个文件,并选择发生时,我得到了同样的异常,它包含<6>

Before I do a selection I load a text file which contains definitely more than 10500 characters as it contains ca. 12000 lines. And then I call EditText.setText() to put the file contents into the field. EditText.setText() works without any problems. First I thought there is something wrong with the file contents, but I loaded another file and when the selection occurred I got the same exception and it contained ends beyond length 10500

推荐答案

这是代码失败的android.text.SpannableStringBuilder中的实际方法.

This is the actual method from android.text.SpannableStringBuilder where your code is failing.

private void checkRange(final String operation, int start, int end) {
    if (end < start) {
        throw new IndexOutOfBoundsException(operation + " " +
                region(start, end) + " has end before start");
    }

    int len = length();

    if (start > len || end > len) {
        throw new IndexOutOfBoundsException(operation + " " +
                region(start, end) + " ends beyond length " + len);
    }

    if (start < 0 || end < 0) {
        throw new IndexOutOfBoundsException(operation + " " +
                region(start, end) + " starts before 0");
    }
}

看起来您的开始/结尾大于EditText中的长度(由length()计算).可能是截断的情况.

It looks like your start/end is greater than the length (calculated by length()) in the EditText. Probably a case of truncation.

就EditText可以容纳的字符数而言,不受Android OS的限制,但可能受设备限制.请参阅 Android TextView中最多9000个字符?,以及

As far as number of characters an EditText can hold is not restricted from Android OS, but probably from device. See Max 9000 characters in Android TextView? and also https://groups.google.com/forum/#!topic/android-developers/JVAm8vBaIQg

这篇关于java.lang.IndexOutOfBoundsException:setSpan(N ... N)结束于长度10500的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆