问题
自从升级到Android 8.0以来,我收到许多崩溃报告,指出IndexOutOfBoundsException
发生在我的代码之外。
崩溃报告
android应用中没有代码负责崩溃,这似乎是Android本身的一个错误。
java.lang.IndexOutOfBoundsException:
at android.text.SpannableStringBuilder.checkRange (SpannableStringBuilder.java:1314)
at android.text.SpannableStringBuilder.setSpan (SpannableStringBuilder.java:680)
at android.text.SpannableStringBuilder.setSpan (SpannableStringBuilder.java:672)
at android.view.accessibility.AccessibilityNodeInfo.setText (AccessibilityNodeInfo.java:2474)
at android.widget.TextView.onInitializeAccessibilityNodeInfoInternal (TextView.java:10357)
at android.view.View.onInitializeAccessibilityNodeInfo (View.java:7307)
at android.view.View.createAccessibilityNodeInfoInternal (View.java:7266)
at android.view.View.createAccessibilityNodeInfo (View.java:7251)
at android.view.accessibility.AccessibilityRecord.setSource (AccessibilityRecord.java:146)
at android.view.accessibility.AccessibilityRecord.setSource (AccessibilityRecord.java:119)
at android.view.View.onInitializeAccessibilityEventInternal (View.java:7203)
at android.widget.TextView.onInitializeAccessibilityEventInternal (TextView.java:10338)
at android.view.View.onInitializeAccessibilityEvent (View.java:7191)
at android.view.View.sendAccessibilityEventUncheckedInternal (View.java:7053)
at android.view.View.sendAccessibilityEventUnchecked (View.java:7038)
at android.view.View.sendAccessibilityEventInternal (View.java:7015)
at android.widget.TextView.sendAccessibilityEventInternal (TextView.java:10725)
at android.view.View.sendAccessibilityEvent (View.java:6982)
at android.widget.TextView.onSelectionChanged (TextView.java:9269)
at android.widget.TextView.spanChange (TextView.java:9505)
at android.widget.TextView$ChangeWatcher.onSpanRemoved (TextView.java:11943)
at android.text.SpannableStringInternal.sendSpanRemoved (SpannableStringInternal.java:408)
at android.text.SpannableStringInternal.removeSpan (SpannableStringInternal.java:243)
at android.text.SpannableString.removeSpan (SpannableString.java:50)
at android.text.Selection.removeSelection (Selection.java:109)
at android.text.method.LinkMovementMethod.onTakeFocus (LinkMovementMethod.java:239)
at android.widget.Editor.onFocusChanged (Editor.java:1163)
at android.widget.TextView.onFocusChanged (TextView.java:9586)
at android.view.View.handleFocusGainInternal (View.java:6593)
at android.view.View.requestFocusNoSearch (View.java:10823)
at android.view.View.requestFocus (View.java:10802)
at android.view.ViewGroup.onRequestFocusInDescendants (ViewGroup.java:3204)
at android.view.ViewGroup.requestFocus (ViewGroup.java:3160)
at android.view.ViewGroup.onRequestFocusInDescendants (ViewGroup.java:3204)
at android.view.ViewGroup.requestFocus (ViewGroup.java:3160)
at android.view.ViewGroup.onRequestFocusInDescendants (ViewGroup.java:3204)
at android.view.ViewGroup.requestFocus (ViewGroup.java:3160)
at android.view.ViewGroup.onRequestFocusInDescendants (ViewGroup.java:3204)
at android.view.ViewGroup.requestFocus (ViewGroup.java:3160)
at android.view.ViewGroup.onRequestFocusInDescendants (ViewGroup.java:3204)
at android.view.ViewGroup.requestFocus (ViewGroup.java:3160)
at android.view.ViewGroup.onRequestFocusInDescendants (ViewGroup.java:3204)
at android.view.ViewGroup.requestFocus (ViewGroup.java:3160)
at android.view.ViewGroup.onRequestFocusInDescendants (ViewGroup.java:3204)
at android.view.ViewGroup.requestFocus (ViewGroup.java:3160)
at android.view.ViewGroup.onRequestFocusInDescendants (ViewGroup.java:3204)
at android.view.ViewGroup.requestFocus (ViewGroup.java:3160)
at android.view.ViewGroup.onRequestFocusInDescendants (ViewGroup.java:3204)
at android.view.ViewGroup.requestFocus (ViewGroup.java:3163)
at android.view.View.requestFocus (View.java:10769)
at android.view.View.requestFocus (View.java:10711)
at android.view.ViewRootImpl.focusableViewAvailable (ViewRootImpl.java:3430)
at android.view.View.setFlags (View.java:13277)
at android.view.View.setVisibility (View.java:9378)
at android.app.Activity.makeVisible (Activity.java:5412)
at android.app.ActivityThread.handleResumeActivity (ActivityThread.java:3785)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2898)
at android.app.ActivityThread.-wrap11 (Unknown Source)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1593)
at android.os.Handler.dispatchMessage (Handler.java:105)
at android.os.Looper.loop (Looper.java:164)
at android.app.ActivityThread.main (ActivityThread.java:6541)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:240)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:767)
可能的原因
因为它发生在TextView
上,我认为它与我使用的这些元素有关:
<TextView
android:id="@+id/txtAlso"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textColor="#0000AA"
android:padding="5dp"
android:textIsSelectable="true"
android:text="" />
尝试过的解决方案
为了有希望修复此错误,我已将TextViews
重写为下面的代码,删除了isSelectable
代码并阻止视图集中。
由于我无法自己重现这个错误,所以希望尽快获得更多信息。如果有人有信息,见解或知道解决方案回复或评论。
<TextView
android:id="@+id/txtAlso"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:textColor="#0000AA"
android:padding="5dp"
android:focusable="false" android:focusableInTouchMode="false"
android:text="" />
答案 0 :(得分:4)
我的应用发生了同样的崩溃。经过大量的研究和测试,我设法重新创建了它。崩溃仅发生在Oreo Android 8.0设备上,几乎只发生在Samsung设备上。
在我的情况下,在单击由Linkify创建的链接时触发了IndexOutOfBounds异常。
Linkify.addLinks(text, path, null, matchFilter, transforFilter);
我删除了Linkify,并找到了另一种无需Linkify即可完成所需工作的方法。