0
我被定義如下創建數據庫表: -光標未正確初始化?
public static final String Create_Database2= "CREATE TABLE " + Table_Name2 + "("
+ play20 + " INTEGER PRIMARY KEY, "
+ play1 + " LONG, "
+ play2 + " LONG, "
+ play3 + " INTEGER, "
+ play4 + " INTEGER, "
+ play5 + " LONG, "
+ play6 + " TEXT, "
+ play7 + " TEXT, "
+ play8 + " TEXT, "
+ play9 + " TEXT, "
+ play10 + " TEXT, "
+ play11 + " INTEGER, "
+ play12 + " INTEGER, "
+ play13 + " INTEGER, "
+ play14 + " INTEGER, "
+ play15 + " INTEGER, "
+ play16 + " INTEGER, "
+ play17 + " TEXT, "
+ play18 + " INTEGER, "
+ play19 + " TEXT"
+ ") ";
現在我從它像這樣得到的數據: -
public Cursor getcontent()
{
Cursor d= database.query(DatabaseHandler.Table_Name2,allColumns,selection, null, null,null,null);
}
public String[] allColumns = { DatabaseHandler.play5, DatabaseHandler.play6,DatabaseHandler.play7,
DatabaseHandler.play8,DatabaseHandler.play9,DatabaseHandler.play10 };
String selection="playlist_id=100813";
以上是我的數據選擇的標準
Cursor r=X.getcontent();
if (r.getCount() > 0) {
r.moveToFirst();
do {
String id = r.getString(r.getColumnIndex("content_id"));
al.add(id);
String from_date =r.getString(r.getColumnIndex("from_date"));
String to_date =r.getString(r.getColumnIndex("to_date"));
String from_time =r.getString(r.getColumnIndex("from_time"));
String to_time =r.getString(r.getColumnIndex("to_time"));
String days =r.getString(r.getColumnIndex("days"));
String duration =r.getString(r.getColumnIndex("duration"));
} while (r.moveToNext()==true);
r.close();
} else {
Log.i("TAG"," No value found");
}
我得到這個錯誤logcat
02-22 15:37:04.565: E/AndroidRuntime(11544): FATAL EXCEPTION: main
02-22 15:37:04.565: E/AndroidRuntime(11544): java.lang.RuntimeException:
Unable to start activity ComponentInfo{com.example.webdata/com.example.webdata.MainActivity}:java.lang.IllegalStateException:
Couldnt read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
我在做什麼錯在這裏?
您可以檢查的getContent()不返回空? – Anukool 2013-02-22 10:16:56
是的,它不返回空我已經檢查過它 – 2013-02-22 10:21:27
所以我認爲它明確..嘗試在database.query()方法中傳遞正確的參數。 – Anukool 2013-02-22 10:31:33