【问题标题】:Android. Strange crash in charAt (setSelection)安卓。 charAt (setSelection) 中的奇怪崩溃
【发布时间】:2013-12-11 21:01:45
【问题描述】:

我在应用程序中有一个非常奇怪的崩溃。 堆栈跟踪:

java.lang.IndexOutOfBoundsException: charAt: -1 < 0
at android.text.SpannableStringBuilder.charAt(SpannableStringBuilder.java:112)
at android.text.Selection.setSelection(Selection.java:84)
at android.text.Selection.setSelection(Selection.java:127)
at android.widget.Editor$InsertionHandleView.updateSelection(Editor.java:4971)
at android.widget.Editor$HandleView.positionAtCursorOffset(Editor.java:4647)
at android.widget.Editor$HandleView.updatePosition(Editor.java:4675)
at android.widget.Editor$PositionListener.onPreDraw(Editor.java:2714)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:711)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2097)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1179)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4859)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:532)
at android.view.Choreographer$FrameHandler.handleMessage(Choreographer.java:664)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5328)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)

我的应用程序包(类/方法)上没有任何链接的堆栈跟踪。 有没有人遇到过这个问题?谢谢。

编辑

您能看到,堆栈跟踪在我的应用程序的包/类上没有任何链接,但应用程序还是崩溃了。

UPD 我使用 Selection.setSelection。我不使用 SpannableStringBuilder。

@Override
public void afterTextChanged(Editable s) {
    if (!s.toString().isEmpty()) {
        Selection.setSelection(s, s.length());
    }   
}

【问题讨论】:

  • 你在为 charAt(index) 传递什么?
  • 请给我们看一些代码
  • IndexOutOfBoundsException
  • 你能把 s.length 改成 s.length-1 并检查一下吗?

标签: android selection indexoutofboundsexception charat


【解决方案1】:

这似乎是一个操作系统错误,需要某个操作系统版本(例如 4.1.2)和某个设备(例如 Galaxy S3 I9300)的组合。这不是你的问题。不幸的是,我也不知道如何解决这个问题。

我很好奇您是如何遇到这个问题的。根据调用堆栈,我的猜测是您点击文本视图并尝试从剪贴板粘贴文本。

【讨论】:

【解决方案2】:

阅读第一行...上面写着java.lang.IndexOutOfBoundsException: charAt: -1 &lt; 0。问题是您的字符串没有您要搜索的字符。贴出代码。那我们看看有什么问题……

【讨论】:

  • 你看,堆栈跟踪在我的应用程序的包/类上没有任何链接,但应用程序还是崩溃了。
  • 好吧,你在哪里使用SpannableStringBuilder
  • @Override public void afterTextChanged(Editable s) { if (!s.toString().isEmpty()) { Selection.setSelection(s, s.length()); }
猜你喜欢
  • 1970-01-01
  • 2013-11-16
  • 2019-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-11-01
  • 2023-02-02
相关资源
最近更新 更多