ListView和Adapter Crash问题的分析和解决
来源:互联网 发布:城市智能交通大数据 编辑:程序博客网 时间:2024/04/20 07:49
发现情况
正在做一个设备控制app,需要阻塞接受下位机发送的can数据,当数据发送过快,10ms一次的时候,app crash 报错:
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.
原因查找
根据报错信息找到报错位置:
protected void layoutChildren() { ***************************************** 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() + ")]"); } *****************************************
根据代码发现 mItemCount != mAdapter.getCount()
分析
原因是由于我在子线程中更新数据,在主线程中更新ui。比如你在handler处理同步主线程中 为mItemCount,而这时候子线程add(data),mAdapter.getCount()就加1。这时候mItemCount != mAdapter.getCount();
解决
把数据更新的操作也放到主线程中。这样的话即使1ms发一次数据 app 也不会crash。
0 0
- ListView和Adapter Crash问题的分析和解决
- 初学ListView和Adapter的分析和总结
- ListView 和 Adapter 的基础
- ListView和Adapter的基础知识
- ListView 和 Adapter 的基础
- ListView 和 Adapter 的基础
- ListView 和 Adapter 的基础
- ListView和Adapter的基础
- ListView 和 Adapter 的基础
- ListView 和 Adapter 的基础
- ListView和Adapter的用法
- ListView 和 Adapter 的基础
- ListView 和 Adapter 的基础
- ListView 和 Adapter 的基础
- ListView和Adapter的学习
- ListView 和 Adapter 的基础
- ListView和GridView 自定义Adapter的getView()方法调用问题
- Listview和 Adapter
- The web application [] appears to have started a thread named [Thread-
- binary
- 类似微博那种局部TableView
- 数值分析:矩阵求逆-奇异性、条件数
- 关于ARM的统一编制与内存映射机制
- ListView和Adapter Crash问题的分析和解决
- 微软面试百题005——SBT再解第K数问题
- 通过socket登陆MySQL
- 【Python】|JSON序列化与反序列化
- jquery change()时间
- 数据结构与算法题目集(中文)4-10 二分查找 (20分)
- android中的mvp模式(二)
- c++ 函数模板 类模板
- (*(volatile unsigned long *) 地址)