ОШИБКА:
java.lang.IllegalStateException: Не удалось прочитать строку 0, столбец 1 из CursorWindow. Убедитесь, что курсор инициализирован правильно, прежде чем получить доступ к данным из него.
Я хочу получить весь список объектов из базы данных sqlite. Но я не знаю, что такое ошибка, потому что я использую запрос Райта для получения списка.
public List<LocationAdress> getLocalList() {
SQLiteDatabase db = getReadableDatabase();
List<LocationAdress> locationsList = new ArrayList<>();
// Select All Query
String selectQuery = "SELECT * FROM " + DataFields.LOCATION_TABLE;
Cursor cursor = db.rawQuery(selectQuery, null);
/* String[] columns = {
DataFields.Col_LATITUDE,
DataFields.COL_LONGITUDE,
DataFields.COL_IMAGE,
DataFields.COL_LIKE,
DataFields.COL_COMMENTS
};*/
/* Cursor cursor = db.query(DataFields.LOCATION_TABLE, columns, null,
null, null, null, null, null);
// looping through all rows and adding to list*/
if(cursor!=null && cursor.getCount() > 0) {
if (cursor.moveToFirst()) {
do {
try {
LocationAdress locationAdress = new LocationAdress();
locationAdress.setLatitude(cursor.getString(cursor.getColumnIndex(DataFields.Col_LATITUDE)));
locationAdress.setLikes(cursor.getString(cursor.getColumnIndex(DataFields.COL_LIKE)));
locationAdress.setImage(cursor.getBlob(cursor.getColumnIndex(DataFields.COL_IMAGE)));
locationAdress.setComments(cursor.getString(cursor.getColumnIndex(DataFields.COL_COMMENTS)));
locationAdress.setLongitude(cursor.getString(cursor.getColumnIndex(DataFields.COL_LONGITUDE)));
locationsList.add(locationAdress);
} catch (Exception e) {
e.printStackTrace();
}
} while (cursor.moveToNext());
}
}
db.close();
return locationsList;
}