简体   繁体   English

android中的java.lang.IllegalStateException?

[英]java.lang.IllegalStateException in android?

I am using three tabs.when i click the tab, an activity starts that displays multiple listview with header.For that i use listadapter and my code seems adapter.addsection ("Header String",new ArrayAdapter(this,R.layout.row,cursor,from,to); then i set list using list.setadapter(adapter).It all works fine when i click the tab.My problem occurs, after i scroll my listview which is in another activity and press emulator back button and clicking tab.Now when i am clicking tab,my application crashes and logcat shows the following error. 我正在使用三个选项卡。单击选项卡时,将启动一个显示带有标题的多个列表视图的活动。为此,我使用listadapter,我的代码似乎是adapter.addsection ("Header String",new ArrayAdapter(this,R.layout.row,cursor,from,to);然后我使用list.setadapter(adapter)设置列表。当我单击选项卡时,一切都很好。当我滚动另一个活动中的listview并按模拟器后退按钮并现在,当我单击选项卡时,我的应用程序崩溃并且logcat显示以下错误。

 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(-1, class android.widget.ListView) with Adapter(class com.t.s.SeperatedListAdapter)]

Whats the solution for this? 有什么解决方案呢? I used adapter.notifydatasetchanged() to solve this.Eventhough i couldn't. 我用adapter.notifydatasetchanged()解决了这个问题。

the reason is: your data is changed, when back to previous activity, the listview will auto refresh, this time system found the data changed but no notifyDataChanged invoke, so throw the error. 原因是: 您的数据已更改,回到上一个活动时,列表视图将自动刷新,这一次系统发现数据已更改,但没有notifyDataChanged调用,因此引发了错误。

so if another activity change the data, you can try: in your previous activity in method: onResume , try use notifyDataChanged to notify. 因此,如果另一个活动更改了数据,则可以尝试:在方法: onResume上一个活动中,尝试使用notifyDataChanged进行通知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM