2

我根据这个 Vogella 教程创建了几个数据访问对象,但我遇到了其中一个问题。当应用程序恢复时,我对其运行了一些查询,我偶尔会在标题中收到错误。具体来说,我运行执行以下三种方法:

public List<Event> getPendingEvents() {
    openReadable();
    List<Event> events = new ArrayList<Event>();

    Cursor cursor = localDb.query(EventTable.TABLE_EVENT,
            allColumns, allColumns[8] + " = ?", new String[] {"pending"}, null, null, null);

    cursor.moveToFirst(); // crash here:  Cannot perform this operation because the connection pool has been closed.
    while (!cursor.isAfterLast()) {
        events.add(cursorToEvent(cursor));
        cursor.moveToNext();
    }

    cursor.close();
    return events;
}

然后在它们全部运行后关闭数据库连接。为什么查询后连接池会关闭?我正在努力想一个理由。它会以某种方式与数据库文件的大小有关吗?这些表特别是并且将永远非常小(< 50 条记录),但其他表会产生影响吗?我唯一的另一个想法是它与 onResume 的工作方式有关。

有人知道吗?

4

0 回答 0