使用粘贴时EditText崩溃:致命异常:java.lang.IndexOutOfBoundsException:98,-81

时间:2016-09-26 06:03:49

标签: java android android-edittext

我在我的应用程序中使用EditText,我在复制/粘贴操作期间看到有时会崩溃应用程序。不幸的是,我无法复制错误或从未遇到错误,但有很多人在体验它。

我正在附加日志:

Fatal Exception: java.lang.IndexOutOfBoundsException: 98, -81
   at android.text.PackedIntVector.deleteAt(PackedIntVector.java:218)
   at android.text.DynamicLayout.reflow(DynamicLayout.java:308)
   at android.text.DynamicLayout.access$000(DynamicLayout.java:41)
   at android.text.DynamicLayout$ChangeWatcher.reflow(DynamicLayout.java:650)
   at android.text.DynamicLayout$ChangeWatcher.onSpanChanged(DynamicLayout.java:679)
   at android.text.SpannableStringBuilder.sendSpanChanged(SpannableStringBuilder.java:1019)
   at android.text.SpannableStringBuilder.sendToSpanWatchers(SpannableStringBuilder.java:601)
   at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:532)
   at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:465)
   at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:38)
   at android.widget.TextView.paste(TextView.java:9130)
   at android.widget.TextView.onTextContextMenuItem(TextView.java:8940)
   at com.paprbit.dcoder.ui.widget.DcoderEditor.onTextContextMenuItem(DcoderEditor.java:881)
   at android.widget.Editor$ActionPopupWindow.onClick(Editor.java:3047)
   at android.view.View.performClick(View.java:4825)
   at android.view.View$PerformClick.run(View.java:20144)
   at android.os.Handler.handleCallback(Handler.java:815)
   at android.os.Handler.dispatchMessage(Handler.java:104)
   at android.os.Looper.loop(Looper.java:194)
   at android.app.ActivityThread.main(ActivityThread.java:5537)
   at java.lang.reflect.Method.invoke(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:956)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751)

这是我的代码:

 @Override
public boolean onTextContextMenuItem(
        final int id) {
    boolean handled = false;
    switch (id) {
        case CodeNow.ID_UNDO:
            handled = true;
            if (canUndo()) {
                undo();
            }
            break;
        case CodeNow.ID_REDO:
            handled = true;
            if (canRedo()) {
                redo();
            }
            break;

    }
    if (handled) {
        return true;
    } else {
        return super.onTextContextMenuItem(id);
    }

}

我的xml代码我在哪里添加了edittext

<com.paprbit.dcoder.ui.widget.DcoderEditor
                        android:id="@+id/et_code_content"
                        style="?editTextDcoderEditor"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:gravity="top"
                        android:textCursorDrawable="@drawable/cursor" />

和此edittext的样式

 <style name="EditTextDcoderEditor">
    <item name="android:textSize">15sp</item>
    <item name="android:layout_marginTop">2dp</item>
    <item name="android:selectAllOnFocus">false</item>
    <item name="android:imeOptions">flagNoExtractUi</item>
    <item name="android:inputType">textNoSuggestions|textMultiLine</item>
    <item name="android:paddingLeft">1dp</item>
    <item name="android:paddingTop">1dp</item>
    <item name="android:paddingBottom">1dp</item>
    <item name="android:paddingRight">10dp</item>
    <item name="android:isScrollContainer">true</item>
</style>

0 个答案:

没有答案