最近,我们在应用程序中遇到了很多崩溃,这是由于Android内部抛出IndexOutOfBoundsException。
Fatal Exception: java.lang.IndexOutOfBoundsException: setSpan (-1 ... -1) starts before 0
at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1331)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:685)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:677)
at android.view.accessibility.AccessibilityNodeInfo.replaceClickableSpan(AccessibilityNodeInfo.java:2925)
at android.view.accessibility.AccessibilityNodeInfo.setText(AccessibilityNodeInfo.java:2889)
at android.widget.TextView.onInitializeAccessibilityNodeInfoInternal(TextView.java:12028)
at android.view.View.onInitializeAccessibilityNodeInfo(View.java:8925)
at android.view.View.createAccessibilityNodeInfoInternal(View.java:8884)
at android.view.View.createAccessibilityNodeInfo(View.java:8869)
at android.view.AccessibilityInteractionController.populateAccessibilityNodeInfoForView(AccessibilityInteractionController.java:396)
at android.view.AccessibilityInteractionController.findAccessibilityNodeInfoByAccessibilityIdUiThread(AccessibilityInteractionController.java:358)
at android.view.AccessibilityInteractionController.access$500(AccessibilityInteractionController.java:74)
at android.view.AccessibilityInteractionController$PrivateHandler.handleMessage(AccessibilityInteractionController.java:1547)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:210)
at android.os.Looper.loop(Looper.java:299)
at android.app.ActivityThread.main(ActivityThread.java:8302)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1037)
在堆栈溢出中找到答案Android SpannableStringBuilder IndexOutOfBoundsException但未找到任何答案
我已经尝试重现,但没有运气,有一个尝试,如果设备有对讲和应用程序崩溃,但不确定所有用户都激活了这个对讲
我很乐意听到任何关于问题的想法:)
1条答案
按热度按时间qgzx9mmu1#
考虑您是否在项目中使用过
SpannableString
和NoCopySpan
。当用户启用辅助功能时会发生此错误。您可以从下面提供的线索跟踪源代码。android.view.accessibility.AccessibilityNodeInfo#setText
android.view.accessibility.AccessibilityNodeInfo#replaceClickableSpan
SpannableStringBuilder
但是,如果不使用
NoCopySpan
,则可能导致内存泄漏。我个人的解决方案是放弃它们的使用,并使用替代组件重构该部分中的代码。If you understand Chinese, you can refer to a post for more detailed information.