java.lang.ArrayIndExoutofBoundSexception调用TextView GetlineEnd时

发布于 2025-02-06 19:44:03 字数 1707 浏览 1 评论 0原文

我将TextView Maxline设置为5,当我致电GetlineEnd(4)时,它肯定具有5个以上的线路,它给了我ArrayIndIndexOutOfBoundSexception。我不知道为什么会发生这种情况。请帮忙吗?谢谢!

logs

06-12 02:50:42.256 30175 30175 E ErrorPageActivity: java.lang.ArrayIndexOutOfBoundsException: length=27; index=30
06-12 02:50:42.256 30175 30175 E ErrorPageActivity:     at android.text.StaticLayout.getLineStart(StaticLayout.java:1151)
06-12 02:50:42.256 30175 30175 E ErrorPageActivity:     at android.text.Layout.getLineEnd(Layout.java:1409)
06-12 02:50:42.256 30175 30175 E ErrorPageActivity:     at com.imdb.livingroom.firetv.util.TextViewExtensionsKt.visibleText(TextViewExtensions.kt:13)

textViewExtensions

fun TextView.visibleText(): String {
    val end = layout.getLineEnd(4)
    return layout.text.toString().substring(0,end);
}

布局xml

<TextView
        android:id="@+id/user_review_description"
        style="@style/text_body_two"
        android:layout_width="@dimen/review_description_width"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/micro_margin"
        android:ellipsize="end"
        android:maxLines="5"
        android:layout_marginStart="@dimen/medium_margin"
        android:importantForAutofill= "noExcludeDescendants"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/user_nickname"
        />

这是视图的图片。详细的评论块是有问题的文本视图

”在此处输入图像描述”

I have the TextView maxLine set to 5 and when I call getLineEnd(4) on a view that most definitely has 5+ lines it gives me the ArrayIndexOutOfBoundsException. I can't figure out why this is happening. please help? Thanks!

logs

06-12 02:50:42.256 30175 30175 E ErrorPageActivity: java.lang.ArrayIndexOutOfBoundsException: length=27; index=30
06-12 02:50:42.256 30175 30175 E ErrorPageActivity:     at android.text.StaticLayout.getLineStart(StaticLayout.java:1151)
06-12 02:50:42.256 30175 30175 E ErrorPageActivity:     at android.text.Layout.getLineEnd(Layout.java:1409)
06-12 02:50:42.256 30175 30175 E ErrorPageActivity:     at com.imdb.livingroom.firetv.util.TextViewExtensionsKt.visibleText(TextViewExtensions.kt:13)

TextViewExtensions

fun TextView.visibleText(): String {
    val end = layout.getLineEnd(4)
    return layout.text.toString().substring(0,end);
}

layout xml

<TextView
        android:id="@+id/user_review_description"
        style="@style/text_body_two"
        android:layout_width="@dimen/review_description_width"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/micro_margin"
        android:ellipsize="end"
        android:maxLines="5"
        android:layout_marginStart="@dimen/medium_margin"
        android:importantForAutofill= "noExcludeDescendants"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/user_nickname"
        />

Here’s a picture of the view. The detailed review block is the textview in question

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流星番茄 2025-02-13 19:44:03

通过将其更改为val end = layout.getLineEnd(Layout.linecount -1)

fixed by changing it to val end = layout.getLineEnd(layout.lineCount - 1)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文