listview 遇到问题java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
开发的时候 遇到 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的更多相关文章
- java.lang.StringIndexOutOfBoundsException: String index out of range: 0
hibernet 报错 java.lang.StringIndexOutOfBoundsException: String index out of range: 0 处理方法 数据表字段为char ...
- 【Spring】java.lang.IndexOutOfBoundsException: Index: 256, Size: 256
Spring接受前台的数据超过256出现例如以下异常: org.springframework.beans.InvalidPropertyException: Invalid property 'sp ...
- 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 ...
- 滑动RecyclerView时出现异常: java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid item position 6(offset:6).state:30
RecyclerView 存在的一个明显的 bug 一直没有修复: java.lang.IndexOutOfBoundsException: Inconsistency detected. Inval ...
- RecycleView错误: java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder
1.错误 java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positi ...
- exception java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
1.情景展示 Java 报错信息如下: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 2.原因分析 首先,这是越界异常,但不是数组越 ...
- java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection still allocated.
java.lang.IllegalStateException: Invalid use of BasicClientConnManager: connection still allocated.M ...
- Android中RecyclerView出现java.lang.IndexOutOfBoundsException
在RecyclerView更细数据时出现java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder ...
- IDEA报错Error:Module 'shop-common' production: java.lang.IndexOutOfBoundsException
问题描述: 本来项目是正常的,编译.运行.启动都是OK的,但是在一次电脑重启后,出现了以上这个问题:Error:Module 'shop-common' production: java.lang.I ...
随机推荐
- asp.net mvc 部署在IIS7.5上出现的[没有相关的源行]错误的解决办法
今天在IIS7.5上部署一个MVC小项目的时候出现以下错误:C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET File ...
- jq 图片裁剪
1.html <div class="jcropbox" style="display: none"> <img src="&quo ...
- 【深度解析】Google第二代深度学习引擎TensorFlow开源
作者:王嘉俊 王婉婷 TensorFlow 是 Google 第二代深度学习系统,今天宣布完全开源.TensorFlow 是一种编写机器学习算法的界面,也可以编译执行机器学习算法的代码.使用 Tens ...
- 【模板】【凸包】Graham_scan
/* 唐代李白 <江夏别宋之悌> 楚水清若空,遥将碧海通.人分千里外,兴在一杯中. 谷鸟吟晴日,江猿啸晚风.平生不下泪,于此泣无穷. */ #include <iostream> ...
- gSoap实现ONVIF中xsd__anyType到具体结构类型的转换
上一篇文章已经粗略计划要讨论gsoap关于序列化/解析编程. 本文则阐述一下关于gsoap生成代码的一些重要特征方法及使用.如题,下我们从ONVIF生成的C码中,挑选简单的一个类型来试验一下与xsd_ ...
- lmsw - 加载机器状态字
将源操作数加载到机器状态字,即寄存器 CR0 的位 0 到 15.源操作数可以是 16 位通用寄存器或内存位置.只有源操作数的低 4 位(也就是 PE.MP.EM 及 TS 标志)会加载到 CR0.C ...
- atoi的实现
#include <iostream> using namespace std; int atoi(char* s) { int retval=0; int n=1; if (*s=='- ...
- 屏蔽手势UIGestureRecognizer 先后响应
在iOS5一下对于手势的识别能力并不强,比如iOS6上面按钮的一个tap事件,最先接收的是uiview,并相应,而不是最上面的button,这时候就需要判断手势所在的位置和手势所在的控制器了 如下例子 ...
- bzoj1563: [NOI2009]诗人小G
Description Input Output 对于每组数据,若最小的不协调度不超过1018,则第一行一个数表示不协调度若最小的不协调度超过1018,则输出"Too hard to arr ...
- android中使用intent来实现Activity带数据跳转
大家都知道startActivity()是用来切换跳转Activity的.如果想要在另个Activity中出书数据的话.只需要在源activity中使用intent.putExtra()方法传出数据. ...