Indexoutofboundsexception with listview

后端 未结 5 348
抹茶落季
抹茶落季 2020-12-21 06:28

I just got a strange indexoutofboundsexception that I can\'t seem to reproduce. It seems to be related to my listactivity:

java.lang.IndexOutOfBoundsExceptio         


        
5条回答
  •  -上瘾入骨i
    2020-12-21 07:04

    I met the same issue when use ListView with header view or footer view to add/remove. So tried different approaches on Stack Overflow, I found a work around solutions to ignore this errors which to handle dispatchDraw method as below.

    public class CustomListView extends ListView{
    
       @Override
       protected void dispatchDraw(Canvas canvas) {
          try {
              super.dispatchDraw(canvas);
          } catch (IndexOutOfBoundsException e) {
              Log.e("luna", "Ignore list view error ->" + e.toString());
          }
       }
    }
    

    Hope that can help u.

    Please refer to this link How to debug Android java.lang.IndexOutOfBoundsException HeaderViewListAdapter.java line

    Have Fun@.@

提交回复
热议问题