I keep getting this error
07-10 21:50:06.296: ERROR/Database(538): android.database.sqlite.SQLiteException: no such table: task: , while compiling: INSERT INTO task(descrip, time, title, date, status) VALUES(?, ?, ?, ?, ?);
When I execute this line of code. Am I inserting it the wrong way?
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();
}
};
Here is my SQL database insert method:
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));
}
}
You're inserting into table "task" but your create statement calls the table "reminders". Got your table names mixed up?
You need to reinstall the app for the changes to take effect. Delete the app and reinstall it, or the db will presist if you just continue to run on your existing apk.
精彩评论