java.lang.ArrayIndExoutofBoundSexception调用TextView GetlineEnd时
我将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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过将其更改为
val end = layout.getLineEnd(Layout.linecount -1)
fixed by changing it to
val end = layout.getLineEnd(layout.lineCount - 1)