【原创】关于Adapter的The content of the adapter has changed问题分析
关于Adapter的The content of the adapter has changed问题分析
1、问题描述
07-28 17:22:02.162: E/AndroidRuntime(16779): 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. Make sure your adapter calls notifyDataSetChanged() when its content changes. [in ListView(2131034604, class android.widget.ListView) with Adapter(class com.nodin.sarah.HeartListAdapter)] 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.ListView.layoutChildren(ListView.java:1555) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.AbsListView.onLayout(AbsListView.java:2091) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.View.layout(View.java:14785) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.ViewGroup.layout(ViewGroup.java:4631) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.View.layout(View.java:14785) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.ViewGroup.layout(ViewGroup.java:4631) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.FrameLayout.onLayout(FrameLayout.java:388) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.View.layout(View.java:14785) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.ViewGroup.layout(ViewGroup.java:4631) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1589) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.View.layout(View.java:14785) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.ViewGroup.layout(ViewGroup.java:4631) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.View.layout(View.java:14785) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.ViewGroup.layout(ViewGroup.java:4631) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.FrameLayout.onLayout(FrameLayout.java:388) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.View.layout(View.java:14785) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.ViewGroup.layout(ViewGroup.java:4631) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.LinearLayout.onLayout(LinearLayout.java:1434) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.View.layout(View.java:14785) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.ViewGroup.layout(ViewGroup.java:4631) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.widget.FrameLayout.onLayout(FrameLayout.java:388) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.View.layout(View.java:14785) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.ViewGroup.layout(ViewGroup.java:4631) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1985) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1742) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5582) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.Choreographer.doCallbacks(Choreographer.java:562) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.Choreographer.doFrame(Choreographer.java:532) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.os.Handler.handleCallback(Handler.java:733) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.os.Handler.dispatchMessage(Handler.java:95) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.os.Looper.loop(Looper.java:137) 07-28 17:22:02.162: E/AndroidRuntime(16779): at android.app.ActivityThread.main(ActivityThread.java:4998) 07-28 17:22:02.162: E/AndroidRuntime(16779): at java.lang.reflect.Method.invokeNative(Native Method) 07-28 17:22:02.162: E/AndroidRuntime(16779): at java.lang.reflect.Method.invoke(Method.java:515) 07-28 17:22:02.162: E/AndroidRuntime(16779): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777) 07-28 17:22:02.162: E/AndroidRuntime(16779): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593) 07-28 17:22:02.162: E/AndroidRuntime(16779): at dalvik.system.NativeStart.main(Native Method) 07-28 17:22:02.162: W/ActivityManager(588): Force finishing activity
2、复现场景
3、原因分析
// Handle the empty set by removing all views that are visible
// and calling it a day
if (mItemCount == 0) {
resetList();
invokeOnItemScrollListener();
return;
} else if (mItemCount != mAdapter.getCount()) {
throw new 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(" + getId() + ", " + getClass()
+ ") with Adapter(" + mAdapter.getClass() + ")]");
}
4、解决方案
- 确保Adapter的数据更新后一定要调用notifyDataSetChanged()方法通知ListView
- 数据更新和notifyDataSetChanged()放在UI线程内,且必须同步顺序执行,不可异步
- 仔细检查确认getCount()方法返回值是否正确
【原创】关于Adapter的The content of the adapter has changed问题分析的更多相关文章
- 【转】关于Adapter的The content of the adapter has changed问题分析 关于Adapter的The content of the adapter has changed问题分析
原文网址:http://www.cnblogs.com/monodin/p/3874147.html 1.问题描述 1 07-28 17:22:02.162: E/AndroidRuntime(167 ...
- ListView:The content of the adapter has changed but ListView did not receive a notification终极解决方法
使用ListView时遇到如下的异常信息: 10-26 18:30:45.085: E/AndroidRuntime(7323): java.lang.IllegalStateException: T ...
- 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 ...
- 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 ...
- Android The content of the adapter has changed but ListView did not receive a notification终极解决方法
这几天做一个自动扫描SD卡上所有APK文件的小工具,扫描过程中会把APK添加到LISTVIEW中显示,结果出现以下错误:(有时候触摸更新数据时候,触摸listview也会报错) E/AndroidRu ...
- Android报错:The content of the adapter has changed...与Channel is unrecoverably broken and will be disposed的分析与解决办法
在Android中adapter错误: The content of the adapter has changed but ListView did not receive a notificati ...
- 【转】解决java.lang.IllegalStateException: The content of the adapter has changed but ListView...的问题
原文网址:http://blog.csdn.net/ueryueryuery/article/details/20607845 我写了一个Dialog,Dialog中有一个ListView,想要点Li ...
- Android开发-- The content of the adapter has changed but ListView did not receive a notification - With AsyncTask
最近在联系开发DaysMatter时遇到一个问题: app中使用ListView来展示所有事件,每次添加完事件后使用下面代码来更新ListView. toDoListView.refreshDrawa ...
- 问题解决:The content of the adapter has changed but ListView did not receive a notification
1. 不要在后台线程中直接调用adapter 2. 不要在后台线程中修改adapter绑定的数据 如果对adapter或者adapter绑定的数据是在线程中,加上runOnUiThread就可以了 r ...
随机推荐
- 0x0A和0x0D
这里主要是在windows下面做的小实验,linux没有试 先贴源码 #include <iostream> #include <string> #include <st ...
- android selector
android 选择器的使用 1.在drawable文件夹下面建一个xml文件,如item.xml,在eclipse中有selector这个选项 2.可以在布局文件.xml(配置android:lis ...
- android继承Dialog实现自定义对话框
有时需要自定义对话框,可以使用AlterDialog.Bulider,比如下面的代码片段 new AlertDialog.Builder(self) .setTitle("标题") ...
- 清除IE中Ajax缓存,Chrome不需要
做项目的时候,会遇到这种情况,通过ajax从后台获取的数据在chrome上显示的是最新的,而在IE上却是以前的数据,这是为什么呢,在我百般调试下终于发现原来是因为IE的ajax缓存的原因,于是加上这段 ...
- 查看JVM内存
你知道如何进行JVM内存查看,这里和大家分享几个JVM内存查看方法,希望对你的学习有所帮助,通常情况下可以用代码查看,也可以在eclipse中增添相关信息后直接查看. JVM内存查看方法 可以用代码查 ...
- Entity Framework走马观花之把握全局
在深入学习某项技术之前,应该努力形成对此技术的总体印象,并了解其基本原理,本文的目的就在于此. 一.理解EF数据模型 EF本质上是一个ORM框架,它需要把对象映射到底层数据库中的表,为此,它使用了三个 ...
- Readhat Linux5.5 安装SVNService(经验总结)
Subversion独立服务和与apache整合服务. 一 .Svn独立服务安装 操作系统: Redhat Linux5.5 安装包获取: 下载 http://subversion.tigris.or ...
- 查看python selenium的api
打开命令行工具,doc中输入: python -m pydoc -p 然后在浏览器中访问http://localhost:4567/,此时应该可以看到python中所有的Modules 按ctrl+f ...
- 1.C#基础篇-->封装、继承和多态
面向对象三要素:封装.继承和多态.正确理解这三个要素,才能在编程中建立面向对象的思想. 1.封装使用篇 作用:好的封装增加代码的可读性,易于维护. 什么情况下使用封装,封装的原则是? 1>功能相 ...
- 【Python】可变对象和不可变对象
Python在heap中分配的对象分成两类:可变对象和不可变对象.所谓可变对象是指,对象的内容是可变的,例如list.而不可变的对象则相反,表示其内容不可变. 不可变对象:int,string,flo ...