首页 > 代码库 > android listview Caused by: java.lang.ArrayIndexOutOfBoundsException: length=3; index=3
android listview Caused by: java.lang.ArrayIndexOutOfBoundsException: length=3; index=3
android listview 适配器在多种类型viewType报错:
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=3; index=3 2 at android.widget.AbsListView$RecycleBin.addScrapView(AbsListView.java:6822) 3 at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5179) 4 at android.widget.AbsListView.scrollIfNeeded(AbsListView.java:3558) 5 at android.widget.AbsListView.onTouchMove(AbsListView.java:3969) 6 at android.widget.AbsListView.onTouchEvent(AbsListView.java:3783) 7 at android.widget.ListView.onTouchEvent(ListView.java:4219) 8 at android.view.View.dispatchTouchEvent(View.java:8556) 9 at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2403) 10 at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2096) 11 at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2409) 12 at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2110) 13 at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2409) 14 at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2110) 15 at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2409) 16 at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2110) 17 at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2409) 18 at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2110) 19 at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2409) 20 at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2110) 21 at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2409) 22 at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2110) 23 at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2409) 24 at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2110) 25 at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2455) 26 at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1756) 27 at android.app.Activity.dispatchTouchEvent(Activity.java:2780) 28 at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2412) 29 at android.view.View.dispatchPointerEvent(View.java:8751) 30 at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4200) 31 at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4066) 32 at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3606) 33 at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3659) 34 at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3625) 35 at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3742) 36 at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3633) 37 at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3799) 38 at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3606) 39 at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3659) 40 at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3625) 41 at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3633) 42 at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3606) 43 at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5901) 44 at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5875) 45 at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5846) 46 at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6012) 47 at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185) 48 at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method) 49 at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:176) 50 at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:5962) 51 at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:6035)
解决方案:http://stackoverflow.com/questions/2596547/arrayindexoutofboundsexception-with-custom-android-adapter-for-multiple-views-in
The item view type you are returning from
getItemViewType()
is >= getViewTypeCount()
.
也就是你的viewType的type类型必须从0开始,{0,1,2,3...}这样的.
typecount大于最后一个类型的type即可.
这样就解决了,ListView多种viewType滑动到底,上滑崩溃的现象.
android listview Caused by: java.lang.ArrayIndexOutOfBoundsException: length=3; index=3
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。