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 ...
随机推荐
- 【CF39E】【博弈论】What Has Dirichlet Got to Do with That?
Description You all know the Dirichlet principle, the point of which is that if n boxes have no less ...
- 简明Vim练级攻略
原文:酷壳网 vim的学习曲线相当的大(参看各种文本编辑器的学习曲线),所以,如果你一开始看到的是一大堆VIM的命令分类,你一定会对这个编辑器失去兴趣的.下面的文章翻译自<Learn Vim P ...
- ecshop 嵌入地图加载不了问题
在ecshop 添加一个标识商家地理位置信息. 百度地图,加载不出来,查了下发现跟 js/transport.js 与 js/utils.js 两个文件有关在需要插入地图的地方去掉这两个文件的引用 地 ...
- 用PHP添加购物商品
<?php session_start(); header ( "Content-type: text/html; charset=UTF-8" ); //设置文件编码格式 ...
- yum版本新增包的一般步骤
在Jekins的自动构建环境中,有时会有在构建出的ISO中添加新应用app需求,对于采用rpm包源代码管理方式的构建环境来说,基本步骤如下: 1.下载app的src.rpm包 2.解压src.rpm包 ...
- Typefaces and Personalities (字体与性格)
Boring afternoon, searching something fun. See this article What Your Favorite Font Says About You , ...
- EntityFramework - Migrations
EntityFramework - Migrations 對項目進行EF的數據庫升級操作.分爲開發環境與部署環境.上的操作總結. 引用: Command說明https://coding.abel.n ...
- 关于system(”pause“);的作用和意义
注意:不要再return 的语句之后加,那样就执行不到了. system() 是调用系统命令:pause 暂停命令: 如果加有 system(”pause“): 这样在运行到此处时,会显示“Pres ...
- javascript summary
Client Javascript HTML5: http://www.html5rocks.com/en/ Libraray: JQuery, JQuery Mobile, Zepto, MoolT ...
- UIAutomation识别UI元素
MS UI Automation(Microsoft User Interface Automation:UIA)是随.net framework3.0一起发布的,虽然在如今这个几乎每天都有各种新名词 ...