2011-07-10 38 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