Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法在使用后续查询时打开数据库文件错误_Android_Sqlite_Cursor - Fatal编程技术网

Android 无法在使用后续查询时打开数据库文件错误

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对象工作正常,但是当我执行另一个查询并将其分配给flightCursor时,它会给出错误

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();
  /* ---------------------- */
}

希望这能解决您的问题

谢谢,我忘记了这一点。