是什么导致 `AutoCompleteTextViews` 出现 `setSpan` 错误?

What is causing a `setSpan` error on `AutoCompleteTextViews`?

问题: 在下面的调试报告中,我想我明白问题是 setSpan 从负值开始,相对于 0。但我不知道是什么那意味着或者我是否可以修复它,因为它没有追溯到任何特定的布局,class 或我创建的函数?我在 activity 中没有处理 setSpan?

的任何代码

似乎发生了什么: 我的 AddNote activity 上的 AutoCompleteTextViews 似乎正在发生。具有讽刺意味的是,这个 activity 在布局和功能上实际上是 EditNote activity 的副本,并且不会出现在 EditNote 中。但是,一个区别是 AddNote activity 它们有 setOnFocusChangedListeners.

从某种意义上说,它也显得随机。有时我只需单击 AutoCompleteTextView 就会触发此错误。其他时候,在 select 编辑或输入数据后,当焦点发生变化时,它就会发生。

预期内容: AutoCompleteTextViews 是带有选项 select 或添加新内容的下拉列表。我已经使用这个 activity 几个月没有问题,然后这才开始发生。

下面,调试没有识别出我的任何 classes 或触发此问题的资源,我只是根据上面的一些细节出现。这就是我不确定它是否可以更改以修复并希望伸出援手的原因之一。

AutoCompleteTextView 对象设置

    ArrayAdapter<String> summaryAdapter = DBQueryTools.captureSummaries(this);
    summary.setThreshold(1);
    summary.setAdapter(summaryAdapter);

    ArrayAdapter<String> topicsAdapter = DBQueryTools.captureDBTopics(this);
    topic.setThreshold(1);
    topic.setAdapter(topicsAdapter);

    ArrayAdapter<String> acQuestionAdapt = DBQueryTools.captureDBQuestions(this);
    question.setThreshold(1);
    question.setAdapter(acQuestionAdapt);

适配器代码

public static ArrayAdapter<String> captureDBTopics(Context context){
    rdb = ResearchDatabase.getInstance(context, "Apologetic.db");
    List<Topics> topics = rdb.getTopicsDao().getTopics();
    List<String> orgTopics = new ArrayList<>();
    for(Topics t : topics){
        orgTopics.add(t.getTopic());
    }
    return new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, orgTopics);
    //topic.setAdapter(topicsAdapter);
}
public static ArrayAdapter<String> captureDBQuestions(Context context){
    rdb = ResearchDatabase.getInstance(context, "Apologetic.db");
    List<Questions> questions = rdb.getQuestionsDao().getQuestions();
    List<String> orgQuestions = new ArrayList<>();
    for(Questions q : questions){
        orgQuestions.add(q.getQuestion());
    }
    return new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, orgQuestions);
    //question.setAdapter(acQuestionAdapt);
}
public static ArrayAdapter<String> captureSummaries(Context context){
    rdb = ResearchDatabase.getInstance(context, "Apologetic.db");
    List<Comments> summaries = rdb.getCommentsDao().getComments();
    List<String> orgSummaries = new ArrayList<>();
    for(Comments c : summaries){
        if(!c.getSummary().isEmpty() && !orgSummaries.contains(c.getSummary().trim()))
            orgSummaries.add(c.getSummary());
    }
    return new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, orgSummaries);
}

调试

E/InputEventReceiver: Exception dispatching input event.
E/MessageQueue-JNI: Exception in MessageQueue callback: handleReceiveCallback
E/MessageQueue-JNI: java.lang.IndexOutOfBoundsException: setSpan (-1 ... -1) starts before 0
        at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1326)
        at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:682)
        at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:674)
        at android.text.Selection.setSelection(Selection.java:93)
        at android.text.Selection.setSelection(Selection.java:77)
        at android.text.method.ArrowKeyMovementMethod.onTouchEvent(ArrowKeyMovementMethod.java:291)
        at android.widget.TextView.onTouchEvent(TextView.java:10089)
        at android.view.View.dispatchTouchEvent(View.java:12513)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
        at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:440)
        at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1830)
        at android.app.Activity.dispatchTouchEvent(Activity.java:3400)
        at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
        at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
        at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:398)
        at android.view.View.dispatchPointerEvent(View.java:12752)
        at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5106)
        at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4909)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4426)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4479)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4445)
        at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4585)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4453)
        at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4642)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4426)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4479)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4445)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4453)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4426)
        at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7092)
        at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7061)
        at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7022)
        at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7195)
        at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:186)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:326)
        at android.os.Looper.loop(Looper.java:160)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.mistywillow.researchdb, PID: 27233
    java.lang.IndexOutOfBoundsException: setSpan (-1 ... -1) starts before 0
        at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1326)
        at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:682)
        at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:674)
        at android.text.Selection.setSelection(Selection.java:93)
        at android.text.Selection.setSelection(Selection.java:77)
        at android.text.method.ArrowKeyMovementMethod.onTouchEvent(ArrowKeyMovementMethod.java:291)
        at android.widget.TextView.onTouchEvent(TextView.java:10089)
        at android.view.View.dispatchTouchEvent(View.java:12513)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:3030)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2719)
        at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:440)
        at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1830)
        at android.app.Activity.dispatchTouchEvent(Activity.java:3400)
        at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
        at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent(WindowCallbackWrapper.java:69)
        at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:398)
        at android.view.View.dispatchPointerEvent(View.java:12752)
        at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5106)
        at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4909)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4426)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4479)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4445)
        at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4585)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4453)
        at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4642)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4426)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4479)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4445)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4453)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4426)
        at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7092)
        at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7061)
        at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7022)
        at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7195)
        at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:186)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:326)
E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:160)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

这似乎是 Issue Tracker 上发布的常见问题。我对以下似乎相似且已分配的问题添加了评论。 https://issuetracker.google.com/issues/119349156