错误: java.lang.IllegalStateException:无法从CursorWindow读取第0行第1行。在从游标访问数据之前,请确保游标已正确初始化。
我想从sqlite数据库中获取所有对象列表。但是我没有什么错误,因为我正在使用wright查询获取列表。
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;
}