0

我已经被这个问题困扰了2天。我有一个名为Mail_Content_SimpleCursor的自定义 SimpleCursorAdapter ,在我的 MainActivity 中有这些代码:

private Mail_Content_SimpleCursor mail_content_cusor;
private Cursor mail_cursor;
 ListView Mail_contents;
public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
...
Mail_contents = (ListView)findViewById(R.id.mail_list_view_item);
mail_cursor = mDB.getMailData("gmail@gmail.com"); // Cursor query read recods from database
        startManagingCursor(mail_cursor);
        String[] from = new String[]{"mail_From","mail_Subject","mail_Content"};
        int[] to = new int[] {R.id.mail_list_from,R.id.mail_list_subject,R.id.mail_list_content};
        mail_content_cusor = new Mail_Content_SimpleCursor(this, R.layout.main_mail_list_item, mail_cursor, from, to);
Mail_contents.setAdapter(mail_content_cusor);

}

然后,我想更改光标以使用函数获取具有其他条件的其他记录

public void change(){
    mail_cursor = mDB.getMailData("yahoo@gmail.com"); // change where clause in query
    startManagingCursor(mail_cursor);
    mail_content_cusor.changeCursor(mail_cursor);
}

但是 changeCursor 函数使我的应用程序因此错误而崩溃

09-22 14:07:18.189: E/AndroidRuntime(31931): java.lang.IllegalStateException: attempt to re-open an already-closed object: android.database.sqlite.SQLiteQuery (mSql = SELECT * FROM mail_contents WHERE mail_user='gmail@gmail.com') 
4

1 回答 1

0

尝试使用swapCursor代替。

根据文档:

SwapCursor :交换一个新的光标,返回旧的光标。与 changeCursor(Cursor) 不同,返回的旧 Cursor 没有关闭。

于 2013-09-22T08:42:50.987 回答