使用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. [laravel] Laravel - composer install

    #composer installLoading composer repositories with package informationUpdating dependencies (includ ...

  2. Perl的多进程框架(watcher-worker)

    关于perl的多进程,大家可能马上会想到Parallel::ForkManager这个模块.但是今天我们试着自己动手写一个类似的框架:) 该多进程开发模型从开源服务器框架Lighttpd发展而来,核心 ...

  3. .net 第二周学习

    这周更进一步的介绍了.net,通过作业的练习,有那么一点点的成就感,相对于前端,成就感还不是很大,但是我还是会继续加油  学习.net,看着他们周末只能呆在寝室写网页,顿时我就高兴了:        ...

  4. 如何保证DBContext实例上下文唯一

    using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using S ...

  5. maven安装nexus私服

    从nexus官网下载Nexus Repository Manager OSS 2.x的安装包:nexus-2.14.1-01-bundle.tar.gz,3.x版本需要jdk8及以上 解压 tar x ...

  6. noty – jQuery通知插件

    noty是一个jQuery的通知(信息提示)插件,灵活轻便,是一个非常棒的用于替代传统提示对话框的插件. 当前最新版本为2.1.0: 从https://github.com/needim/noty 可 ...

  7. Async and Await 异步和等待

    [第一次这么耐下性子认真写博客,虽然觉得很认真了,当毕竟是第一次嘛,以后再看肯定觉得很不咋滴的,更何况园子里有那么多的高人和大侠,这篇文章就权当练练手了,熟悉一下用客户端发表博客了,也希望大家多多照顾 ...

  8. 【转】优化Web程序的最佳实践

    自动排版有点乱,看着蛋疼,建议下载中文PDF版阅读或阅读英文原文. Yahoo!的Exceptional Performance团队为改善Web性能带来最佳实践.他们为此进行了 一系列的实验.开发了各 ...

  9. 在js中对时间类型格式化字符串

    Date.prototype.toString = function (format) { if (format == null) { format = "yyyy-MM-dd HH:mm: ...

  10. JavaScript正则表达式下——相关方法

    上篇博客JavaScript 正则表达式上——基本语法介绍了JavaScript正则表达式的语法,有了这些基本知识,可以看看正则表达式在JavaScript的应用了,在一切开始之前,看看RegExp实 ...