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

前端 未结 4 714
梦如初夏
梦如初夏 2021-01-06 05:34

I have an app which loads a listview when opened, however I am getting an Array Index Out Of Bounds Exception, with no clues as to where the problem lies. It is trying to ac

相关标签:
4条回答
  • 2021-01-06 05:46

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

    0 讨论(0)
  • 2021-01-06 05:48

    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.

    0 讨论(0)
  • 2021-01-06 05:54

    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.

    0 讨论(0)
  • 2021-01-06 06:04

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

    0 讨论(0)
提交回复
热议问题