ListView random IndexOutOfBoundsException on Froyo

前端 未结 2 1051
无人共我
无人共我 2020-12-03 01:16

I have an app with tons of downloads and I\'m receiving a lot of this error:

 16783         AndroidRuntime  E  java.lang.IndexOutOfBoundsException: Invalid i         


        
2条回答
  •  [愿得一人]
    2020-12-03 02:07

    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.

提交回复
热议问题