Так что, по сути, я дважды запрашиваю DB. Я не понимаю, откуда эта ошибка возникает, потому что я нигде не закрываю базу данных. Код, который возвращает ошибку, выполняется следующим образом. Я проверил, и я просто видел такой случай, как мой.попытка повторно открыть уже закрытый объект: sqlitequery
BeaconHandler pullAllDB = new BeaconHandler(this);
try {
List<Beacon> beaconsShown = pullAllDB.getAllBeacons();
for (final Beacon bn : beaconsShown) {
try {
int messageCount = pullAllDB.getMessageCount();
Log.d("Message", messageCount + " Messages Found");
if (messageCount > 0) {
//Do Something
} else {
// Do Nothing
}
}
catch (Exception e) {
e.getStackTrace();
Log.e("Message", e.getMessage());
}
}
}
И код делает запросы ...
public int getBeaconsCount() {
String countQuery = "SELECT * FROM " + TABLE_BASIC_BEACON;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
cursor.close();
// return count
return cursor.getCount();
}
public int getMessageCount() {
String mcountQuery = "SELECT * FROM " + MESSAGE_BEACON;
SQLiteDatabase mdb = this.getReadableDatabase();
Cursor mcursor = mdb.rawQuery(mcountQuery, null);
mcursor.close();
// return count
return mcursor.getCount();
}
Ничего себе, я не могу поверить, что я не брал на себя, что. Полагаю, иногда вам просто нужен еще один набор глаз. – TheHamstring