我的数据已成功添加到数据库中。我已通过调试代码对其进行了检查。但是当我使用游标读取此数据时,它会引发以下异常:
java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
这是我的数据库辅助函数代码:
`///get schools
public ArrayList<SchoolModel> getSchools() {
school.clear();
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery("select * from School", null);
if ((cursor.getCount() >0)){
if (cursor.moveToFirst()) {
do {
SchoolModel item = new SchoolModel();
item.SchoolID = cursor.getInt(cursor
.getColumnIndex("SchoolID "));
item.Address= cursor.getString(cursor
.getColumnIndex("Address"));
item.Cell= cursor.getString(cursor
.getColumnIndex("Cell"));
item.ContactPerson= cursor.getString(cursor
.getColumnIndex("ContactPerson"));
item.Description= cursor.getString(cursor
.getColumnIndex("Description"));
item.Phone= cursor.getString(cursor
.getColumnIndex("Phone"));
item.AreaID = cursor.getInt(cursor
.getColumnIndex("AreaID"));
school.add(item);
} while (cursor.moveToNext());
}
}
cursor.close();
db.close();
return school;
}
谁能告诉我我做错了什么?