错误提示:

at android.widget.AbsListView$RecycleBin.addScrapView(AbsListView.java:)

在Android中给ListView写多个不同的item布局的时候,我遇到了一个标题中的数组越界错误,事实上这个错误之前我已经遇到过。但这次我还是又一次认识了一下这个错误的产生原因。

错误原因:

给ListView编写多个item条目的时候,我们须要在Adapter适配器中重写 getItemViewType()getViewTypeCoun() 两个方法,我们通常在 getItemViewType() 中给详细的item做区分(这两个方法的返回值类型都为 int 类型),以便在 getView() 载入不同的 layout 布局,而在 getViewTypeCount() 方法中定义一共同拥有多少种不同的item,导致标题中的错误出现的原因。能够使用

answertab=votes#tab-top%20StackOverFlow" title="stackoverflow">StackOverflow 中的一句话来解释:“The item view type you are returning from getItemViewType() is >= getViewTypeCount().”。中文意思就是 getViewTypeCount() 的值必须大于 getItemViewType() 的值,反之,则会出现标题中的错误,通常,我们从 1 開始给不同的item设置 Type 类型。举个栗子来说。我们设置了 Type为1 和 Type为2的item类型,然后在 getViewTypeCount() 方法中返回了 2。 这种话 getViewTypeCount() 的值就和Type为2的时候返回值相等了。于是出现了标题所看到的的数据越界错误,通常我们把 Type 值设置为从0開始计数就可以保证最大值的 Type 类型也不会大于 getViewTypeCount() 方法的返回值。getItemViewType() 源代码中的凝视也提醒我们:”Integers must be in the range 0 to {@link #getViewTypeCount} - 1“。

參考链接:

http://lmbj.net/blog/arrayindexoutofboundsexception/

http://www.cnblogs.com/xitang/p/3197158.html

at android.widget.AbsListView$RecycleBin.addScrapView(AbsListView.java:)的更多相关文章

  1. java.lang.ClassCastException: android.widget.ImageButton异常处理

    在调程序时总是出现异常关闭的现象,log显示: 03-26 07:58:09.528: E/AndroidRuntime(398): Caused by: java.lang.ClassCastExc ...

  2. java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams

    java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.w ...

  3. NullPointerException at android.widget.AbsListView.obtainView at android.widget.ListView.makeAndAddView

    使用ExpandableListView的时候,报如下错.网上搜索发现原来是在CommonNumberQueryAdapter的getGroupView()方法里返回的是null,注意细节哦!!! 1 ...

  4. 解决 android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams

    错误日志1: 06-13 10:55:50.410: E/KVLog(1129): Error info:java.lang.ClassCastException: android.widget.Li ...

  5. 关于java.lang.NoSuchMethodError: android.widget.RelativeLayout.setBackground的解决办法

    今天用一个安卓4.0.4版本的手机测试手上的项目,发现logcat弹出这样一个提示“java.lang.NoSuchMethodError: android.widget.RelativeLayout ...

  6. java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.ProgressBar$SavedState

    java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.Progress ...

  7. java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.TextView

    最近在学习drawerLayout时,遇到这个bug.如下示: java.lang.ClassCastException: android.widget.RelativeLayout cannot b ...

  8. Android开发报错系列(一),java.lang.NullPointerException,at android.widget.ListView.setupChild

    问题描述:运行代码是报空指针错误,java.lang.NullPointerException,at Android.widget.ListView.setupChild 问题定位:listview控 ...

  9. java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.L(转)

    09-09 10:19:59.979: E/AndroidRuntime(2767): FATAL EXCEPTION: main09-09 10:19:59.979: E/AndroidRuntim ...

随机推荐

  1. Wannafly挑战赛3

    B遇见 时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 65536K,其他语言131072K64bit IO Format: %lld 题目描述 A和B在同一条路上,他们之间的距离为 k ...

  2. NOJ——聊天止于呵呵(string流重定向+map,水题)

    [1645] 聊天止于呵呵 时间限制: 5000 ms 内存限制: 65535 K 问题描述 (现代版)俗话说:流言止于智者,聊天止于呵呵.输入一段聊天记录,你的任务是数一数有 多少段对话“止于呵呵” ...

  3. HDU-1529 Cashier Employment

    据网上说这是到差分约束四星题... 可我觉得难吗? 比推DP方程容易... 两种约束方式,当然实现到程序就变成六种了... #include <cstdio> #include <c ...

  4. POJ-1190 生日蛋糕 NOI99

    深搜+几个剪枝. 貌似搜索顺序也挺重要的...我不知是不是因为这个然后Tle了好久... #include <cstdio> #include <iostream> #incl ...

  5. BZOJ4517 [Sdoi2016]排列计数 【组合数 + dp】

    题目 求有多少种长度为 n 的序列 A,满足以下条件: 1 ~ n 这 n 个数在序列中各出现了一次 若第 i 个数 A[i] 的值为 i,则称 i 是稳定的.序列恰好有 m 个数是稳定的 满足条件的 ...

  6. Java如何获取ISO 8601时间

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); df.setTimeZone(TimeZ ...

  7. 洛谷 [P3455] ZAP

    莫比乌斯函数 #include <iostream> #include <cstdio> #include <cmath> #include <cstring ...

  8. [Codeforces Round #170 Div. 1] 277A Learning Languages

    A. Learning Languages time limit per test:2 seconds memory limit per test:256 megabytes input standa ...

  9. Crash的数字表格 BZOJ 2154 / jzptab BZOJ 2693

    jzptab [问题描述] 求: 多组询问 [输入格式] 一个正整数T表示数据组数 接下来T行 每行两个正整数 表示N.M [输出格式] T行 每行一个整数 表示第i组数据的结果 [样例输入] 1 4 ...

  10. net4:MultiView(view)行为中的commmandname与commmandargument,ListBox的使用及移动操作

    原文发布时间为:2008-07-29 -- 来源于本人的百度文章 [由搬家工具导入] using System;using System.Data;using System.Configuration ...