SQLdatabse错误没有这样的列_id?

时间:2011-07-10 21:26:29

标签: android

07-10 21:24:23.006: ERROR/AndroidRuntime(389): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fttech.taskask/com.fttech.taskask.TaskList}: android.database.sqlite.SQLiteException: no such column: _id: , while compiling: SELECT _id, title, descrip, date, time, type

我是否继续使用此代码获取错误。我不知道是什么原因造成的。因为我有一切都是正确的。 这是我使用的代码

class TaskHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "windowShopper";
private static final int SCHEMA_VERSION = 1;

public TaskHelper(Context context){
    super(context, DATABASE_NAME, null, SCHEMA_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL("CREATE TABLE task (_id   INTEGER   PRIMARY   KEY    AUTOINCREMENT, title TEXT, descrip TEXT, date TEXT, time TEXT, type TEXT)");


}


@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
    // TODO Auto-generated method stub

}

public Cursor getAll(){
    return(getReadableDatabase().rawQuery("SELECT _id, title, descrip, date, time, type", null));

}
public void insert(String title, String descrip, String date, String time, String status){
    ContentValues cv = new ContentValues();
    cv.put("title", title);
    cv.put("descrip", descrip);
    cv.put("date", date);
    cv.put("time", time);
    cv.put("status", status);
    getWritableDatabase().insert("task", "name", cv);
}
public Cursor getById(String id){
    String [] args = {id};

    return(getReadableDatabase()    
            .rawQuery("SELECT _id, title, descrip, date, time, status FROM task WHERE _ID=?",args));


}
public void update(String id, String title, String descrip, String date, String time, String type){
    ContentValues cv = new ContentValues();
    String [] args={id};
    cv.put("title", title);
    cv.put("descrip", descrip);
    cv.put("date", date);
    cv.put("time", time);
    cv.put("status", type);
    getWritableDatabase().update("task", cv, "_ID=?", args);


}
public String getTitle(Cursor c){
    return(c.getString(2));
}
public String getDescrip(Cursor c){
    return(c.getString(3));
}
public String getDate(Cursor c){
    return(c.getString(4));

}
public String getTime(Cursor c){
    return(c.getString(5));
}
public String getStatus(Cursor c){
    return(c.getString(6));
}

}

07-10 21:34:27.476: ERROR/AndroidRuntime(428): Caused by: android.database.sqlite.SQLiteException: no such column: _id: , while compiling: SELECT _id, title, descrip, date, time, type

1 个答案:

答案 0 :(得分:1)

您可能需要将_id包装在引号中,例如“_id”


在看到你的评论之后,逃避不是你所说的问题,这是缺少的FROM条款