Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – java.lang.ArrayIndexOutOfBoundsException when calling TextView getLineEnd

Posted on November 11, 2022 By

Solution 1 :

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

Problem :

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

READ  [FIXED] android's messenger IPC outdated or not working
Powered by Inline Related Posts
Android Tags:android, android-layout, textview

Post navigation

Previous Post: [FIXED] android – How to detect when third party app’s dialog box appears in React native?
Next Post: [FIXED] android – Get the list of user SIM cards and select it – flutter

Related Posts

[FIXED] java – Android: Edit views added programmatically Android
[FIXED] spring boot – Using BCryptPasswordEncoder in android studio? Android
[FIXED] java – Is it okay to filter firebase data using conditions? Will it affect the speed and accuracy of Firebase realtime database? Android
[FIXED] android – How do you define a variable from a future in a widget? Android
[FIXED] android – Sendig a GET request to REST API from phone app Android
[FIXED] Android Studio Unable to generate signed APK Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What is the rising action in Julius Caesar?
  • How do you secure a rope to itself?
  • Does waterproof laminate scratch easily?
  • What makes a building prewar?
  • What can you learn in a month without alcohol?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme