android listview Caused by: java.lang.ArrayIndexOutOfBoundsException: length=3; index=3

简介: android listview 适配器在多种类型viewType报错: Caused by: java.lang.ArrayIndexOutOfBoundsException: length=3; index=32 at android.

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滑动到底,上滑崩溃的现象.

目录
相关文章
|
21天前
|
存储 算法 Java
Java零基础-charAt(int index)详解
【10月更文挑战第20天】Java零基础教学篇,手把手实践教学!
43 4
|
26天前
|
存储 算法 Java
Java零基础-charAt(int index)详解
【10月更文挑战第16天】Java零基础教学篇,手把手实践教学!
15 1
|
2月前
|
Java API Nacos
Caused by: java.lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forge
Caused by: java.lang.IllegalStateException: No Feign Client for loadBalancing defined. Did you forge
137 2
|
2月前
|
Java
flyway报错Caused by: java.lang.NoSuchMethodError: org.flywaydb.core.api.configuration.FluentConfigurat
flyway报错Caused by: java.lang.NoSuchMethodError: org.flywaydb.core.api.configuration.FluentConfigurat
40 2
|
2月前
|
Java Android开发 C++
🚀Android NDK开发实战!Java与C++混合编程,打造极致性能体验!📊
在Android应用开发中,追求卓越性能是不变的主题。本文介绍如何利用Android NDK(Native Development Kit)结合Java与C++进行混合编程,提升应用性能。从环境搭建到JNI接口设计,再到实战示例,全面展示NDK的优势与应用技巧,助你打造高性能应用。通过具体案例,如计算斐波那契数列,详细讲解Java与C++的协作流程,帮助开发者掌握NDK开发精髓,实现高效计算与硬件交互。
137 1
|
3月前
|
存储 搜索推荐 Java
探索安卓开发中的自定义视图:打造个性化UI组件Java中的异常处理:从基础到高级
【8月更文挑战第29天】在安卓应用的海洋中,一个独特的用户界面(UI)能让应用脱颖而出。自定义视图是实现这一目标的强大工具。本文将通过一个简单的自定义计数器视图示例,展示如何从零开始创建一个具有独特风格和功能的安卓UI组件,并讨论在此过程中涉及的设计原则、性能优化和兼容性问题。准备好让你的应用与众不同了吗?让我们开始吧!
|
3月前
|
Java 调度 Android开发
Android经典实战之Kotlin的delay函数和Java中的Thread.sleep有什么不同?
本文介绍了 Kotlin 中的 `delay` 函数与 Java 中 `Thread.sleep` 方法的区别。两者均可暂停代码执行,但 `delay` 适用于协程,非阻塞且高效;`Thread.sleep` 则阻塞当前线程。理解这些差异有助于提高程序效率与可读性。
79 1
|
3月前
|
Java Android开发
解决Android编译报错:Unable to make field private final java.lang.String java.io.File.path accessible
解决Android编译报错:Unable to make field private final java.lang.String java.io.File.path accessible
497 1
|
3月前
|
Android开发
Cannot create android app from an archive...containing both DEX and Java-bytecode content
Cannot create android app from an archive...containing both DEX and Java-bytecode content
37 2
|
3月前
Caused by: java.lang.ClassNotFoundException: javax.servlet.Filter
Caused by: java.lang.ClassNotFoundException: javax.servlet.Filter
66 3