我創建了以下數據庫..柱存在,但沒有顯示
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("create table ITEMS(ROW_ID integer primary key autoincrement,ITEM_DESCRIPTION text,ITEM_AMOUNT integer," +
"time DATETIME DEFAULT CURRENT_DATE);");
db.execSQL("create table payments(PAY_ID integer primary key autoincrement,PAY_DESC text,PAY_AMT integer,date DATETIME DEFAULT CURRENT_DATE);");
}
,我使用下面的函數來檢索支付表項
public Cursor getPayments(){
SQLiteDatabase db=this.getReadableDatabase();
Cursor c=db.rawQuery("select * from " + KEY_PTABLE, null);
for(c.moveToFirst();!c.isAfterLast();c.moveToNext()){
c.getColumnIndexOrThrow("pay_id");
}
return c;
}
和logcat的是showing--
AndroidRuntime(30868): FATAL EXCEPTION: main
**AndroidRuntime(30868): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.expensesdatabase/com.example.expensesdatabase.PayView}: java.lang.IllegalArgumentException: column 'pay_id' does not exist**
AndroidRuntime(30868): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
AndroidRuntime(30868): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
AndroidRuntime(30868): at android.app.ActivityThread.access$600(ActivityThread.java:123)
AndroidRuntime(30868): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
AndroidRuntime(30868): at android.os.Handler.dispatchMessage(Handler.java:99)
AndroidRuntime(30868): at android.os.Looper.loop(Looper.java:137)
AndroidRuntime(30868): at android.app.ActivityThread.main(ActivityThread.java:4424)
AndroidRuntime(30868): at java.lang.reflect.Method.invokeNative(Native Method)
AndroidRuntime(30868): at java.lang.reflect.Method.invoke(Method.java:511)
AndroidRuntime(30868): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
AndroidRuntime(30868): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
AndroidRuntime(30868): at dalvik.system.NativeStart.main(Native Method)
**AndroidRuntime(30868): Caused by: java.lang.IllegalArgumentException: column 'pay_id' does not exist**
AndroidRuntime(30868): at android.database.AbstractCursor.getColumnIndexOrThrow(AbstractCursor.java:267)
AndroidRuntime(30868): at com.example.expensesdatabase.MySQLiteHelper.getPayments(MySQLiteHelper.java:152)
什麼是'KEY_PTABLE'? – laalto
表名..即付款 – droidX
這些字段是否定義爲常量? –