开发的时候 遇到 java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0

这个异常有时候会有,有时候正常 不太好捕捉

猜测 已经把数据给了list,然后让主线程去显示;接着后台继续获取数据。那也许有可能主线程还是没刷新完,后台又把新数据给过来了

所以 猜测 是刷新头部出现的问题

也就是

news.clear();
news.addAll(0, refreshNewData);
newsAdapter.notifyDataSetChanged();

这里出现的问题

所以调整为:

		news.clear();
news.addAll(localNews);
          newsAdapter=new NewsListAdapter(activity, news);
mnews_listview.setAdapter(newsAdapter);
newsAdapter.notifyDataSetChanged();

因为有headview 所以还是有问题 这个时候调整了下headview

变成

			news.clear();
news.addAll(localNews);

              newsAdapter=new NewsListAdapter(activity, news);

     if(mnews_listview.getHeaderViewsCount()>0){

				mnews_listview.removeHeaderView(viewGallery);
}
mnews_listview.addHeaderView(viewGallery);
mnews_listview.setAdapter(newsAdapter);
newsAdapter.notifyDataSetChanged();

  ok 没问题了

应该是异步线程没有及时更新数据造成的 在此备注下

listview 遇到问题java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0的更多相关文章

  1. java.lang.StringIndexOutOfBoundsException: String index out of range: 0

    hibernet 报错 java.lang.StringIndexOutOfBoundsException: String index out of range: 0 处理方法  数据表字段为char ...

  2. 【Spring】java.lang.IndexOutOfBoundsException: Index: 256, Size: 256

    Spring接受前台的数据超过256出现例如以下异常: org.springframework.beans.InvalidPropertyException: Invalid property 'sp ...

  3. hive脚本出现Error: java.lang.RuntimeException: Error in configuring object和Caused by: java.lang.IndexOutOfBoundsException: Index: 9, Size: 9

    是在reduce阶段报的错误,详细错误信息是 朱传豪 19:04:48 Diagnostic Messages for this Task: Error: java.lang.RuntimeExcep ...

  4. 滑动RecyclerView时出现异常: java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 6(offset:6).state:30

    RecyclerView 存在的一个明显的 bug 一直没有修复: java.lang.IndexOutOfBoundsException: Inconsistency detected. Inval ...

  5. RecycleView错误: java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder

    1.错误 java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positi ...

  6. exception java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

      1.情景展示 Java 报错信息如下: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 2.原因分析 首先,这是越界异常,但不是数组越 ...

  7. java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection still allocated.

    java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection still allocated.M ...

  8. Android中RecyclerView出现java.lang.IndexOutOfBoundsException

    在RecyclerView更细数据时出现java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder ...

  9. IDEA报错Error:Module 'shop-common' production: java.lang.IndexOutOfBoundsException

    问题描述: 本来项目是正常的,编译.运行.启动都是OK的,但是在一次电脑重启后,出现了以上这个问题:Error:Module 'shop-common' production: java.lang.I ...

随机推荐

  1. JSP标准标签库的安装以及自定义标签的创建

    JSTL 库安装 Apache Tomcat安装JSTL 库步骤如下: 从Apache的标准标签库中下载的二进包(jakarta-taglibs-standard-current.zip). 官方下载 ...

  2. javascript——事件处理

    <script type="text/javascript"> function EventUtil() { var _self = this; ///添加事件 var ...

  3. mysql更新密码为空

    1.进入命令行 mysql -u root -p 'oldpassword'; 2 修改root用户的密码:mysql> update mysql.user set password=PASSW ...

  4. 【C#枚举】根据EnumName获取Value

    public static int GetEnumValue(Type enumType, string enumName) { try { if (!enumType.IsEnum) throw n ...

  5. mysql 语句资料总结

    一.UNION命令 UNION 操作符用于合并两个或多个 SELECT 语句的结果集. 请注意,UNION 内部的 SELECT 语句必须拥有相同数量的列.列也必须拥有相似的数据类型.同时,每条 SE ...

  6. JavaScript----Performance Tool and Process

    1. Syntax-------------JSLint, JSHint, 2. Combine------------YUI 3. Minify---------------JSMin

  7. Black Box《优先队列》

    Description Our Black Box represents a primitive database. It can save an integer array and has a sp ...

  8. c# 基础连接已经关闭: 连接被意外关闭,错误的解决

    原文:c# 基础连接已经关闭: 连接被意外关闭,错误的解决 调试一个使用HttpWebRequest模拟提交表单的程序的时候频繁出现上述错误提示,google了一下发现了几个解决方案.1.在appli ...

  9. Linux Shell编程(3)——运行shell脚本

    写完一个脚本,你能够运行它用命令:sh scriptname, [5] 另外也也可以用bash scriptname. 来执行(不推荐使用:sh <scriptname, 因为这样会禁止脚本从标 ...

  10. 数据结构(线段树):BZOJ 1018: [SHOI2008]堵塞的交通traffic

    1018: [SHOI2008]堵塞的交通traffic Time Limit: 3 Sec  Memory Limit: 162 MBSubmit: 2638  Solved: 864 Descri ...