Unable to open database file error on using subsequent queries

前端 未结 1 1954
小鲜肉
小鲜肉 2021-01-13 13:53

I have the following code, the first cursor object works fine, but when i do another query and assign it to the flightCursor, it gives the error.

Cursor curs         


        
相关标签:
1条回答
  • 2021-01-13 14:35

    Close your cursor when you're done with it! I think you've just got too many cursor objects open

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

    Hopefully this fixes your issue

    0 讨论(0)
提交回复
热议问题