我一直收到此错误
07-10 21:50:06.296:错误/数据库(538):android.database.sqlite.SQLiteException:没有这样的表:task :,编译时:INSERT INTO任务(描述,时间,标题,日期,状态)VALUES(?,?,?,?,?);
当我执行这行代码时。我插错了吗?
private View.OnClickListener onSave = new View.OnClickListener() {
@Override
public void onClick(View v) {
String type = null;
switch(status.getCheckedRadioButtonId()){
case R.id.completed:
type = "completed";
break;
case R.id.in_progress:
type="in-progress";
break;
}
if(taskId == null){
helper.insert(title.getText().toString(), descrip.getText().toString(), date.getText().toString(), time.getText().toString(), status.toString());
Toast.makeText(getBaseContext(), "Task Saved", Toast.LENGTH_SHORT);
}
else{
helper.update(taskId, title.getText().toString(), descrip.getText().toString(), date.getText().toString(), time.getText().toString(), type);
}
finish();
}
};
这是我的SQL数据库插入方法:
class TaskHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "taskask.db";
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 reminders (_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 FROM reminders ORDER BY title", 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));
}
}
答案 0 :(得分:0)
您正在插入表“task”,但您的create语句会调用表“提醒”。你的桌名混淆了吗?
答案 1 :(得分:0)
您需要重新安装该应用才能使更改生效。删除应用程序并重新安装,或者如果您继续在现有的apk上运行,数据库将自动加注。