今天android程序发生了一个异常,查询日志后发现日志如下:
java.lang.IndexOutOfBoundsException: Invalid index 2, size is 1
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
at java.util.ArrayList.get(ArrayList.java:308)
at android.widget.HeaderViewListAdapter.getView(HeaderViewListAdapter.java:225)
at android.widget.AbsListView.obtainView(AbsListView.java:2440)
at android.widget.ListView.makeAndAddView(ListView.java:1876)
at android.widget.ListView.fillDown(ListView.java:702)
at android.widget.ListView.fillGap(ListView.java:666)
at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5315)
at android.widget.AbsListView.scrollIfNeeded(AbsListView.java:3583)
at android.widget.AbsListView.onTouchMove(AbsListView.java:4002)
at android.widget.AbsListView.onTouchEvent(AbsListView.java:3817)
at android.view.View.dispatchTouchEvent(View.java:9332)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2576)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2257)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2582)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2271)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2582)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2271)
at com.scwang.smartrefresh.layout.SmartRefreshLayout.dispatchTouchEvent(SmartRefreshLayout.java:850)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2582)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2271)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2582)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2271)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2582)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2271)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2582)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2271)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2582)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2271)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2582)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2271)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2582)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2271)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2582)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2271)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2582)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2271)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2582)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2271)
at com.android.internal.policy.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2506)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1792)
at android.app.Activity.dispatchTouchEvent(Activity.java:2870)
at com.android.internal.policy.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2465)
at android.view.View.dispatchPointerEvent(View.java:9564)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4331)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4185)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3703)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3769)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3729)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3868)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3737)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3925)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3703)
at android.view.ViewRootImpl$InputStage.on
我把日志继续找出来,发现是在刷新的时候出错的。而且,当时出错的场景为网络条件下极差的环境。
于是,查询相关资料;查询的资料标识,是由于数据进行清除,但Adapter(界面展示)却进行了刷新,造成界面和实际数据不一致。
解决方法:及时更改数据和刷新数据。
笔者的解决方案:
设置数据和刷新数据在一个过程。
经测试,暂未发现问题。
|