gpt4 book ai didi

android - java.lang.IllegalArgumentException 由于 Spannable TextView

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:34:01 32 4
gpt4 key购买 nike

我在我的 Google Play 控制台中收到了这份崩溃报告,我自己从未遇到过,也无法重现。

java.lang.IllegalArgumentException: 
at android.text.method.WordIterator.checkOffsetIsValid (WordIterator.java:380)
at android.text.method.WordIterator.isBoundary (WordIterator.java:101)
at android.widget.Editor$SelectionStartHandleView.positionAtCursorOffset (Editor.java:4300)
at android.widget.Editor$HandleView.updatePosition (Editor.java:3736)
at android.widget.Editor$PositionListener.onPreDraw (Editor.java:2513)
at android.view.ViewTreeObserver.dispatchOnPreDraw (ViewTreeObserver.java:944)
at android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2417)
at android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1321)
at android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:6708)
at android.view.Choreographer$CallbackRecord.run (Choreographer.java:894)
at android.view.Choreographer.doCallbacks (Choreographer.java:696)
at android.view.Choreographer.doFrame (Choreographer.java:631)
at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:880)
at android.os.Handler.handleCallback (Handler.java:815)
at android.os.Handler.dispatchMessage (Handler.java:104)
at android.os.Looper.loop (Looper.java:207)
at android.app.ActivityThread.main (ActivityThread.java:5728)
at java.lang.reflect.Method.invoke (Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:679)

崩溃报告没有提到哪个类导致了崩溃。我最好的猜测是遵循自定义 TextView

private void customTextView(TextView view) {
SpannableStringBuilder spanTxt = new SpannableStringBuilder(
Html.fromHtml(definition[0]));
spanTxt.append("\n\nExample");
spanTxt.setSpan(new ClickableSpan() {
@Override
public void onClick(View view) {
showAlert();
}
}, spanTxt.length() -"Example".length(), spanTxt.length(), 0);
view.setMovementMethod(LinkMovementMethod.getInstance());
view.setText(spanTxt, TextView.BufferType.SPANNABLE);
}

我自定义的 TextView 有问题吗?

最佳答案

我已经删除了你的 Html.fromHtml(definition[0])\n\n。然后效果很好。请测试这两个东西是否会出现。

private void customTextView(TextView view) {
SpannableStringBuilder spanTxt = new SpannableStringBuilder("Testing");
spanTxt.append("Example");
spanTxt.setSpan(new ClickableSpan() {
@Override
public void onClick(View view) {
Log.e("tag","show click");
}
}, spanTxt.length() -"Example".length(), spanTxt.length(), 0);
view.setMovementMethod(LinkMovementMethod.getInstance());
view.setText(spanTxt, TextView.BufferType.SPANNABLE);
}

交叉检查您的文本是否正常。这一个 Html.fromHtml(definition[0])。不确定你为什么使用 \n\n 它会转到下一行。

检查这两件事。其他人工作得很好。

谢谢。

关于android - java.lang.IllegalArgumentException 由于 Spannable TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49217528/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com