使用ListView时遇到如下的异常信息:

10-26 18:30:45.085: E/AndroidRuntime(7323): java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. [in ListView(2131296280, class android.widget.ListView) with Adapter(class com.souapp.appmanager.ApkListAdapter)]

其实我在listview的adapter添加完数据后,使用了handler去调用datper.notifyDataSetChanged();来通知listview显示变化结果;

虽然自己很确定没有多线程操作,但是有人说listview本来就是线程不安全的,这个不关心了,看了国外一个开发者的方法很简单。

解决方法1:

ListView.requestLayout();  

Adatper.notifyDataSetChanged(); 

在你adpater更新前,调用listview的requestLayout(),这样做无非就是弥补数据数量不一致导致报错,虽然一个解决的好办法。

但是实际上用的时候我发现也会出问题,想了想最彻底的解决办法

彻底解决方法:

把  listview的adapter数据更新和dapter.notifyDataSetChanged()方法的调用必须同时放到单独一个线程里,报错基本是都是这个原因,有人把adapter里的数据更新了,但是 dapter.notifyDataSetChanged() 放到一个单独线程去更新,结果出现notifyDataSetChanged更新同步的问题

以上内容来自:http://blog.csdn.net/changemyself/article/details/8116670

解决更新ListView数据时出现的问题分析总结:

  没仔细读的话,一眼看去就说说在非UI线程去更新了ListVIew的数据,然后下意识的认为是调用adapter.notifyDataSetChanged方法的调用被放到了非UI线程,仔细一看是说更新ListView的数据以及通知数据更新要放到同一个线程(主线程),是为了保持数据一致,adapter里面一般是会存放一个数组,对那个数据的修改和调用notifyDataSetChanged方法要放到一起,而且是放到主线程,如果对数据的更新放到了子线程,notifyDataSetChanged的调用在主线程,notifyDataSetChanged的调用会默认把ListView绑定到主线程里面了,这个时候子线程来更新数据的话就会出现在非UI线程修改UI线程的东西了。

这个问题也不是必崩溃,低版本崩的多,高版本好像崩溃得少

ListView:The content of the adapter has changed but ListView did not receive a notification终极解决方法的更多相关文章

  1. Android The content of the adapter has changed but ListView did not receive a notification终极解决方法

    这几天做一个自动扫描SD卡上所有APK文件的小工具,扫描过程中会把APK添加到LISTVIEW中显示,结果出现以下错误:(有时候触摸更新数据时候,触摸listview也会报错) E/AndroidRu ...

  2. The content of the adapter has changed but ListView did not receive a notification

    java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive ...

  3. Android The content of the adapter has changed but ListView did not receive a notification

    The content of the adapter has changed but ListView did not receive a notification. Make sure the co ...

  4. 【转】解决java.lang.IllegalStateException: The content of the adapter has changed but ListView...的问题

    原文网址:http://blog.csdn.net/ueryueryuery/article/details/20607845 我写了一个Dialog,Dialog中有一个ListView,想要点Li ...

  5. Android开发-- The content of the adapter has changed but ListView did not receive a notification - With AsyncTask

    最近在联系开发DaysMatter时遇到一个问题: app中使用ListView来展示所有事件,每次添加完事件后使用下面代码来更新ListView. toDoListView.refreshDrawa ...

  6. android The content of the adapter has changed but ListView did not receive a notification 错误的解决方案

    使用了AsyncTask在后台刷新适配器,并且通知ui线程更新ListView,运行时发现时不时的出现 如题 的错误, 导致程序崩溃,解决方法如下: 1.建立一个缓冲数据集,这个数据集就是填充适配器的 ...

  7. java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification

    ListView UI重绘时触发layoutChildren, 此时会校验listView的mItemCount与其Adapter.getCount是否相同,不同报错. ListView.layout ...

  8. 问题解决:The content of the adapter has changed but ListView did not receive a notification

    1. 不要在后台线程中直接调用adapter 2. 不要在后台线程中修改adapter绑定的数据 如果对adapter或者adapter绑定的数据是在线程中,加上runOnUiThread就可以了 r ...

  9. The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. Make s

    我出现这个问题是引用资源文件问题 helper.getView(R.id.in_pic).setBackgroundResource(item.getResourceId()); //错的helper ...

随机推荐

  1. 如何判断ScrollView滑动方形

    1/判断滚动视图左右滚动 { CGFloat startContentOffsetX;//滚动开始的坐标 CGFloat willEndContentOffsetX; //滚动即将停止的坐标 CGFl ...

  2. TableLayout表格布局详解

    一.Tablelayout简介 Tablelayout类以行和列的形式对控件进行管理,每一行为一个TableRow对象,或一个View控件.当为TableRow对象时,可在TableRow下添加子控件 ...

  3. 打开mysql时,提示 1040,Too many connections

    打开mysql时,提示 1040,Too many connections,这样就无法打开数据库,看不了表里边的内容了. 出现这个问题的原因是,同时对数据库的连接数过大,mysql默认的最大连接数是1 ...

  4. 作业三(代码规范、代码复审、PSP)

    1.代码规范: 我支持代码要有规范,理由如下. (1).艺术是一个很带有个人风格的学科,天马行空才能凸显出自己的价值.但不要忘了,会艺术的不是生下来就会艺术, 他也需要按照前辈的步骤一步一步的学习基础 ...

  5. 备忘: Install MODI for use with Microsoft Office 201x

    简介 Microsoft Office 2010 中删除了 Microsoft Office Document Imaging (MODI).本文提供了在计算机上安装 MODI 的步骤,还说明了重新获 ...

  6. python 模块加载

    python 模块加载 本文主要介绍python模块加载的过程. module的组成 所有的module都是由对象和对象之间的关系组成. type和object python中所有的东西都是对象,分为 ...

  7. Android多线程分析之三:Handler,Looper的实现

    Android多线程分析之三:Handler,Looper的实现 罗朝辉 (http://www.cnblogs.com/kesalin/) CC 许可,转载请注明出处 在前文<Android多 ...

  8. 浅析Windows安全相关的一些概念

    Session 我们平常所说的Session是指一次终端登录, 这里的终端登录是指要有自己的显示器和鼠标键盘等, 它包括本地登录和远程登录.在XP时代每次终端登录才会创建一个Session,但是在Vi ...

  9. iOS——Core Animation 知识摘抄(四)

    原文地址http://www.cocoachina.com/ios/20150106/10840.html 延迟解压 一旦图片文件被加载就必须要进行解码,解码过程是一个相当复杂的任务,需要消耗非常长的 ...

  10. HTML5 WebStorage

    WebStorage是HTML5中本地存储的解决方案之一,在HTML5的WebStorage概念引入之前除去IE User Data.Flash Cookie.Google Gears等看名字就不靠谱 ...