【问题标题】:IllegalStateException when updating adapter data更新适配器数据时出现 IllegalStateException
【发布时间】:2017-11-28 12:21:15
【问题描述】:

请帮我找到这个错误的修复程序,它出现在生产版本中,我不知道下面日志中的错误到底在哪里。

我从 Crashlytics 得到以下日志报告:

ListView.java line 1557
android.widget.ListView.layoutChildren 

Fatal Exception: 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(2131558802, class 
android.widget.ListView) with Adapter(class 
android.widget.HeaderViewListAdapter)]
   at android.widget.ListView.layoutChildren(ListView.java:1557)
   at android.widget.AbsListView.onTouchEvent(AbsListView.java:3442)
   at android.view.View.dispatchTouchEvent(View.java:7565)
   .
   .
   .

【问题讨论】:

  • 可能你错过了通知数据更改adapter.notifyDataSetChanged();

标签: android listview android-studio android-adapter


【解决方案1】:

您只能从主线程更改数据。

如果您在后台线程中获取数据,请在主线程中等待结果,更改数据,然后调用 adapter.notifyDataSetChanged(),或者使用处理程序从后台线程返回主线程,然后一个 run() 方法。

【讨论】:

    猜你喜欢
    • 2011-05-12
    • 1970-01-01
    • 2016-10-21
    • 1970-01-01
    • 2014-09-18
    • 1970-01-01
    • 2014-08-17
    • 2018-06-28
    • 1970-01-01
    相关资源
    最近更新 更多