listview 中出现的ArrayIndexOutOfBoundsException
来源:互联网 发布:蔡仕伟淘宝 编辑:程序博客网 时间:2024/06/01 08:53
记录一次自己使用listview出现的问题–数组越界。最近在做一个聊天界面,用到了Listview,加载不同类型的布局。然而,一直出现下面的异常,却未提示所在哪一行:
listview java.lang.ArrayIndexOutOfBoundsException: length=2; index=2
查了很久的资料,发现了错误原因。
由于需要ListView的item 显示两种布局,在聊天适配器中需要添加 getItemViewType(int position)
和 getViewTypeCount()
两个方法,错误的写法如下:
public int getItemViewType(int position) { MsgBean msgBean = mDatas.get(position); if (msgBean.getType() == MainActivity.Type.SERVER) return 1; return 2; } @Override public int getViewTypeCount() { return 2; }
这里,view的类型总数为2,那么getItemViewType
方法返回的类型应该为:0,1 ,而不是这里出现的1和2。不要忘了,通常都是以0开始的。
0 0
- listview 中出现的ArrayIndexOutOfBoundsException
- jedis 中出现ArrayIndexOutOfBoundsException异常的解决方法
- ListView getItemViewType ArrayIndexOutOfBoundsException 的解决办法
- ListView用getItemViewType()区分不同item布局的时候出现ArrayIndexOutOfBoundsException
- listview 添加 多种layout时,会出现ArrayIndexOutOfBoundsException
- Android listview ArrayIndexOutOfBoundsException问题
- Android ListView addScrapView ArrayIndexOutOfBoundsException
- Android 解决Listview ArrayIndexOutOfBoundsException
- ListView中使用type需要注意的东西 java.lang.ArrayIndexOutOfBoundsException: length=2; index=2 addScrapView
- butterKnife出现ArrayIndexOutOfBoundsException
- 关于Java中对数组进行冒泡排序时出现ArrayIndexOutOfBoundsException异常时的分析和处理方法
- ListView报错:ListView中使用type需要注意的东西 java.lang.ArrayIndexOutOfBoundsException: length=2; index=2 addScr
- android使用getItemViewType时出现java.lang.ArrayIndexOutOfBoundsException的错误
- TextView 显示内容时出现 ArrayIndexOutOfBoundsException 的解决方法(Android 4.1)
- Java Swing编程的时候使用JTable出现ArrayIndexOutOfBoundsException问题
- ArrayIndexOutOfBoundsException listview 不同视图问题
- ListView中显示的条目出现重复
- 解决listview中出现重复的项
- 站在巨人的肩膀上(一)
- JZOJ 4700 简单DP
- Android无线调试程序
- HDU1571
- 分布式缓存技术redis学习系列(三)——redis高级应用(主从、事务与锁、持久化)
- listview 中出现的ArrayIndexOutOfBoundsException
- jzoj 4710. 【NOIP2016提高A组模拟8.17】Value 贪心+动态规划
- iOS控件:状态栏
- leetcode-java-110. Balanced Binary Tree
- 设计模式-状态模式
- 验证数学黑洞 ,用户输入一个四位数,输出变换到6174的过程
- 分布式缓存技术redis学习系列(四)——redis高级应用(集群搭建、集群分区原理、集群操作)
- LA 7457 Discrete Logarithm Problem(shank的大步小布算法)
- velociyt判断变量是否为null