0

嗨,每次我安装应用程序时,打开它而不是用后退按钮关闭它,然后再次重新打开它,我得到同样的错误:

05-05 10:49:35.453: ERROR/AndroidRuntime(5118): 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(2131361820, class android.widget.ListView) with Adapter(class com.TVSpored.ChannelItemAdapter)]

我读过我必须制作 onRestart 函数(LINK)......但我不知道如何处理它......

onCreate 函数执行以下操作:

  1. 设置布局
  2. 设置所有必要的对象(ProgressDialog、ArrayList、ChannelItemAdapter、channelDBAdapter)
  3. 在 asynctask 中加载数据:new LoadChannels().execute(channelItem);

正如我之前所说,它在 onStart 和浏览应用程序时完美运行......但是当离开应用程序并重新启动它时,它总是崩溃......

谢谢你的帮助!


添加代码:

protected ArrayList<ToDoItem> doInBackground(ArrayList<ToDoItem>... passing) 
{

    cItems = passing[0]; //get passed arraylist
    toDoListCursor = channelDBAdapter. getAllToDoItemsCursor();
    startManagingCursor(toDoListCursor);
    channelItem.clear();
    if (toDoListCursor.moveToFirst())
    do 
    { 
      String task = toDoListCursor.getString(toDoListCursor.getColumnIndex(ToDoDBAdapter.KEY_NAME));
      String created = toDoListCursor.getString(toDoListCursor.getColumnIndex(ToDoDBAdapter.KEY_EPG_NAME));
      int fav = toDoListCursor.getInt(toDoListCursor.getColumnIndex(ToDoDBAdapter.KEY_FAV));
      int id = toDoListCursor.getInt(toDoListCursor.getColumnIndex(ToDoDBAdapter.KEY_EPG_ID));
      int ch_type = toDoListCursor.getInt(toDoListCursor.getColumnIndex(ToDoDBAdapter.KEY_CH_CHTYPE_ID));
      int country = toDoListCursor.getInt(toDoListCursor.getColumnIndex(ToDoDBAdapter.KEY_CH_COU_ID));
      ToDoItem newItem = new ToDoItem(task, created, fav, id, ch_type, country);
      channelItem.add(0, newItem);
    } 
    while(toDoListCursor.moveToNext());


    return cItems; //return result
}
4

1 回答 1

0

从您提供的堆栈跟踪来看,您似乎在 UI 线程之外修改了 ListView 适配器的内容。我认为您应该查看您的 ASyncTask 以确保您仅对在 UI 线程中执行的方法(例如,不在 doInBackground 中)执行适配器的修改。

请参阅异步任务

于 2011-05-05T09:10:41.380 回答