Cursor cursor=myDatabase.rawQuery("select ids,title,times from goodtime" , null);
cursor.moveToFirst();
while(!cursor.isAfterLast()){
int id=cursor.getInt(cursor.getColumnIndex("ids"));
String title=cursor.getString(cursor.getColumnIndex("title"));
String times=cursor.getString(cursor.getColumnIndex("times"));
System.out.println(title);
System.out.println(cursor.getColumnIndex("bj"));
String beijing=cursor.getString(cursor.getColumnIndex("bj"));
上面是我的代碼,title還是可以正常查找的,但是bj這個變量的值確實-1,同時報出錯誤java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.notebook/com.example.notebook.Notebook}: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
這是我創建的表:
String ml="create table goodtime(ids integer PRIMARY KEY autoincrement,title text,content text,times text,ptpath text,mppath text,vdpath text,islock integer,password text,bj text)";
arg0.execSQL(ml);
網上說有可能大小寫不對,我仔細查看了變量名都是一致的啊
求各位大神幫我看一下,指點一下我,先謝謝了!
看下你的數據庫中有沒有對應的記錄