Android List View Array Index Out Of Bounds Exception - No clues?

不羁的心 提交于 2019-11-30 22:42:55

This is caused by setting android:ellipsize="middle" (or start) on a TextView that does not have android:singleLine="true" on.

For example, the following crashes on this error:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ellipsize="middle"
    android:maxLines="1"
    android:text="blahblahblahblahblahblahblahblahblahbla---go really long" />

But the following does not:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ellipsize="middle"
    android:singleLine="true"
    android:text="blahblahblahblahblahblahblahblahblahbla---go really long" />

Reference: https://code.google.com/p/android/issues/detail?id=33868

Note: singleLine is a deprecated attribute but still works on Jelly Bean.

your problem is in the getView method , this method will be called whenever u scroll through your array so make sure u check if the view is not null before doing any logic there.

Check your layouts and cursor column name array lengths in the CursorAdapter's constructor. When the two array's length mismatch, it causes ArrayOutOfBoundsException.

This is definitely related to text view ellipsize logic, It has nothing to do with adapter code.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!