我有以下数据库配置
public static final String ST_ID = "s_id";
public static final String ST_NAME = "s_name";
public static final String ST_COURSE = "s_course";
public static final String DBCREATE_STUDENTDB = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME+" ("
+ "s_id INTEGER PRIMARY KEY AUTOINCREMENT, "
+ "s_name VARCHAR, "
+ "s_course VARCHAR);";
public static final int VERSION = 1;
现在我正在尝试获取个人 ID
final ContentResolver resolver = getContentResolver();
final String[] projection = { StudentDB.ST_NAME, StudentDB.ST_COURSE };
Cursor cursor = resolver.query(StudentDataProvider.studentTableUri, projection, null, null, null);
if (cursor.moveToFirst()) {
do {
Log.wtf("ID", ""+cursor.getString(cursor.getColumnIndex(StudentDB.ST_ID)));
} while (cursor.moveToNext());
}
我在这方面遇到了错误。
10-02 07:14:29.788: E/AndroidRuntime(2252): java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
但是以下代码适用于其他列
Log.wtf("List", ""+cursor.getString(cursor.getColumnIndex(StudentDB.ST_COURSE)));
问题是什么?