开发的时候 遇到 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. 使用IDEA,利用SpringMVC框架建立HelloWorld项目

    无论是从头开始学习一门新的语言还是技术,我们的入门都是从HelloWorld开始,也许就是因为这样,我在学习Spring MVC的时候,就有一种偏执,一定要写出一个HelloWorld来.研究了好久, ...

  2. 浅谈KMP算法及其next[]数组

    KMP算法是众多优秀的模式串匹配算法中较早诞生的一个,也是相对最为人所知的一个. 算法实现简单,运行效率高,时间复杂度为O(n+m)(n和m分别为目标串和模式串的长度) 当字符串长度和字符集大小的比值 ...

  3. cocos2d-x 之 CCArray 源码分析

    cocos2d-x 自己实现了一个数组CCArray ,下面我们来分析一下CCArray的源码 CCArray继承CCObject,所以,CCArray也具有引用计数功能和内存自动管理功能. 数组的源 ...

  4. 【POJ1733】【带标记并查集】Parity game

    Description Now and then you play the following game with your friend. Your friend writes down a seq ...

  5. form WebBrowser自动点击弹出提示框alert、弹出对话框confirm、屏蔽弹出框、屏蔽弹出脚本错误的解决办法

    针对WebBrowser控件中自动点击弹出框及禁用脚本提示问题得到如下几种实际情况的解决办法,绝对管用. 1.屏蔽弹出错误脚本 将WebBrowser控件ScriptErrorsSuppressed设 ...

  6. PHPCMS v9 自定义表单添加验证码验证

    1. 在 \phpcms\templates\default\formguide\show.html 中添加验证码显示 <input type="text" id=" ...

  7. cloudera目录位置

    http://www.aboutyun.com/thread-9189-1-1.html 这里来的嘿嘿. 1. 相关目录/var/log/cloudera-scm-installer : 安装日志目录 ...

  8. 测试gcc的优化选项

    一.测试准备及原理 测试代码: static void wait(volatile unsigned long dly) { ; dly--); } int main(void) { unsigned ...

  9. python Hbase Thrift pycharm 及引入包

    cp -r hbase/ /usr/lib/python2.7/site-packages/ 官方示例子http://code.google.com/p/hbase-thrift/source/bro ...

  10. hibernate 多对一的情况

    <?xml version="1.0" encoding="GBK"?> <!DOCTYPE hibernate-mapping PUBLIC ...