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

时间: 2024-10-24 03:39:40

android listview Caused by: java.lang.ArrayIndexOutOfBoundsException: length=3; index=3的相关文章

ListView中使用type需要注意的东西 java.lang.ArrayIndexOutOfBoundsException: length=2; index=2 addScrapView

ListView中使用type需要注意的东西 在使用ListView时,如果使用了getItemViewType, 记得他的值一定要是从0开始计数的. 且要覆盖getViewTypeCount方法.并且让getViewTypeCount>getItemViewType 否则会有数组越界异常: 10-21 20:18:16.231: E/AndroidRuntime(4475): java.lang.ArrayIndexOutOfBoundsException: length=3; index=3

Android BaseAdapter加载多个不同的Item布局时出现UncaughtException in Thread main java.lang.ArrayIndexOutOfBoundsException: length=15; index=15

java.lang.ArrayIndexOutOfBoundsException: length=15; index=15 异常出现的场景:在做聊天界面时,需要插入表情,图片,文字,名片,还有几种较为复杂的布局.这时就需要用到BaseAdapter中的getViewTypeCount()和getItemViewType(int position) 方法了,在发送复杂界面时出现了这个异常. 令人抓狂的是这个异常居然是UncaughtException,根本无法判断哪一行出错了,刚开始的时候觉得一定

Java - 错误: "java.lang.ArrayIndexOutOfBoundsException: length=1; index=1"

错误: "java.lang.ArrayIndexOutOfBoundsException: length=1; index=1" 本文地址: http://blog.csdn.net/caroline_wendy/article/details/24464947 Java中, 错误: "java.lang.ArrayIndexOutOfBoundsException: length=1; index=1" ; 意思: 数组(Array)索引(Index)越界(Ou

AndroidStudio编译出现Caused by: java.lang.ArrayIndexOutOfBoundsException: 4其中一种的原因

Caused by: java.lang.ArrayIndexOutOfBoundsException: 4 at com.android.tools.profiler.asm.ClassReader.a(Unknown Source) at com.android.tools.profiler.asm.ClassReader.a(Unknown Source) at com.android.tools.profiler.asm.ClassReader.a(Unknown Source) at

captcha报错java.lang.ArrayIndexOutOfBoundsException

*captcha报错java.lang.ArrayIndexOutOfBoundsException 启动程序时发现了如下错误信息,纠结了好久 Caused by: java.lang.ArrayIndexOutOfBoundsException: 0 at sun.font.CompositeFont.getSlotFont(CompositeFont.java:375) at sun.font.CompositeGlyphMapper.initMapper(CompositeGlyphMap

Android Caused by: java.lang.IllegalArgumentException: column '_id' does not exist

出错原因:在查询整个sqlite数据库时,没有查询到 "_id" 这一列. 原来的代码是:mSQLiteDatabase.query(table_name, new String[] {_title}, null, null, null, null, null); 修改后的代码为:mSQLiteDatabase.query(table_name, null, null, null, null, null, null); 这里的 new String[] {MyEvent._title}

Android项目编译的时候出现:Caused by: java.lang.ClassNotFoundException: com.example.aaa.MainActivity

错误类型: 04-28 06:10:15.508: E/AndroidRuntime(849): Caused by: java.lang.ClassNotFoundException: com.example.aaa.MainActivity 04-28 06:10:15.508: E/AndroidRuntime(849): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61) 04-28 06:1

Eclipse中使用recyclerview时出现Caused by: java.lang.NoClassDefFoundError: android.support.v7.recyclerview.R$styleable

转自: http://blog.csdn.net/chenleicpp/article/details/46848785 程序崩溃,错误提示: Caused by: java.lang.NoClassDefFoundError: android.support.v7.recyclerview.R$styleable 原因: 在eclipse中使用RecyclerView,编译没有问题,但是运行时候会出现如下错误,百思不得其解,又说v4包与v7包版本不一致,有说没有导入v7-compat包的,经反

android Caused by: java.lang.IllegalArgumentException: Binary XML file line #7: Must specify unique

今天写了一个静态得fragment,好久没写了,一写就出现问题了,先看下布局文件 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height=&qu