java.lang.IndexOutOfBoundsException: getChars (7 … 0) has end before start

后端 未结 5 2203
梦毁少年i
梦毁少年i 2020-12-19 20:36

My users are sending unhandled exceptions to me via http://code.google.com/p/android-remote-stacktrace/

I am getting the following but have no idea what it means.

相关标签:
5条回答
  • 2020-12-19 20:47

    It's a known bug in the Android framework. Here's a link to the issue.

    0 讨论(0)
  • 2020-12-19 20:47

    if android couldnt set the selection you do that using cursor position... i resolved the issue by putting this exactly before the crashing line

    editor.setSelection(editor.getText().length(), editor.getText().length());
    
    0 讨论(0)
  • 2020-12-19 20:53

    Its Late but yesterday i figure out this problem. The Problem is in your case is your end is before start like 7....0 which is wrong if you want to highlight a text you start should be less then your end. Check out posted example its perfectly working.

    The Answer is for those Who still has this issue.

     String searchText = "Your search String";
            String qr_code = "Your String";
    
            int length = searchText.length();
            if (length > 0) {
                //color your text here
                int index = qr_code.indexOf(searchText);
                SpannableString sb = new SpannableString(qr_code);
                ForegroundColorSpan fcs = new ForegroundColorSpan(getResources().getColor(R.color.colorAccent));
                sb.setSpan(fcs, index, (index+length), Spanned.SPAN_EXCLUSIVE_INCLUSIVE)
                holder.textViewShortCode.setText(sb);
            } else {
                textViewShortCode.setText(Html.fromHtml(qr_code));
            }
    
    0 讨论(0)
  • 2020-12-19 20:56

    For anyone still struggling with this issue, placing the following code in your Activity's onResume will solve it:

    textEntry.setSelection(textEntry.getText().length(), textEntry.getText().length());
    
    0 讨论(0)
  • 2020-12-19 21:00

    I fixed it with a custom textEntry. Changed onSelectionChanged and put there the code from loopj!

    My code:

    @Override
    protected void onSelectionChanged(int selStart, int selEnd) {
        if (selStart >= 0) {
            super.onSelectionChanged(selStart, selEnd);
        } else {
            setSelection(getText().length());
        }
    }
    
    0 讨论(0)
提交回复
热议问题