2011-07-10 41 views
0
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 

是我一直使用此代碼得到的錯誤。我不知道是什麼導致它。因爲我擁有一切。 這裏是我的代碼使用SQLdatabse錯誤沒有這樣的列_id?

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

您可能需要包裝_id引號像這樣 「_id」


看到您的評論退讓並不之後這個問題如你所說,它是在缺少FROM子句

+0

我試過了,我張貼的錯誤我得到這個問題的底部。檢查出來 – yoshi24

+2

見更新答案 –

+0

我想通了。 – yoshi24