ListView random IndexOutOfBoundsException on Froyo

After a lot of time checking the android source code and not understanding this error I’ve finally cracked it.

The problem occurs with Samsung phones, they have a different implementation on the over-scroll functionality and that ended up throwing this exception as it tried to select a footer/header out of bounds (even when there is no footer view).

The solution I used is not pretty but it will stop this error from happening ever again.

class MyFixedListView extends ListView {
    @Override
    protected void dispatchDraw(Canvas canvas) {
        try {
            super.dispatchDraw(canvas);
        } catch (IndexOutOfBoundsException e) {
            // samsung error
        }
    }
}

Now I use this ListView implementation and the error is gone.

I really hope this helps anyone using endless adapters.

Leave a Comment