Android 无法在使用后续查询时打开数据库文件错误
我有下面的代码,第一个cursor对象工作正常,但是当我执行另一个查询并将其分配给flightCursor时,它会给出错误Android 无法在使用后续查询时打开数据库文件错误,android,sqlite,cursor,Android,Sqlite,Cursor,我有下面的代码,第一个cursor对象工作正常,但是当我执行另一个查询并将其分配给flightCursor时,它会给出错误 Cursor cursor = database.query( CityAndAirportsTable.notificationsTable, new String[] { CityAndAirportsTable.notifyFlightId }, null, null, null, null, "Id DESC" );
Cursor cursor = database.query( CityAndAirportsTable.notificationsTable, new String[] { CityAndAirportsTable.notifyFlightId },
null, null, null, null, "Id DESC" );
cursor.moveToFirst();
while( !cursor.isAfterLast() ){
String id = String.valueOf( cursor.getInt( 0 ) );
Cursor flightCursor = database.query( CityAndAirportsTable.flightTable, new String[] { CityAndAirportsTable.fromDestinationCode,
CityAndAirportsTable.toDestinationCode, CityAndAirportsTable.currentPrice }, CityAndAirportsTable.flightId + "=" + id,
null, null, null, null );
}
在flightCursor=database.query中,我得到了错误
Cursor cursor = database.query( CityAndAirportsTable.notificationsTable, new String[] { CityAndAirportsTable.notifyFlightId },
null, null, null, null, "Id DESC" );
cursor.moveToFirst();
while( !cursor.isAfterLast() ){
String id = String.valueOf( cursor.getInt( 0 ) );
Cursor flightCursor = database.query( CityAndAirportsTable.flightTable, new String[] { CityAndAirportsTable.fromDestinationCode,
CityAndAirportsTable.toDestinationCode, CityAndAirportsTable.currentPrice }, CityAndAirportsTable.flightId + "=" + id,
null, null, null, null );
}
日志
关于stackoverflow也有类似的问题,但在我的例子中,第一个查询有效,但第二个查询失败。完成后关闭光标!我想你打开的光标对象太多了
Cursor cursor = database.query( CityAndAirportsTable.notificationsTable, new String[] { CityAndAirportsTable.notifyFlightId },
null, null, null, null, "Id DESC" );
cursor.moveToFirst();
while( !cursor.isAfterLast() ){
String id = String.valueOf( cursor.getInt( 0 ) );
Cursor flightCursor = database.query(
CityAndAirportsTable.flightTable,
new String[] { CityAndAirportsTable.fromDestinationCode,
CityAndAirportsTable.toDestinationCode,
CityAndAirportsTable.currentPrice },
CityAndAirportsTable.flightId + "=" + id,
null, null, null, null );
/* Close the cursor here! */
flightCursor.close();
/* ---------------------- */
}
希望这能解决您的问题谢谢,我忘记了这一点。