我正在创建一个todo任务应用程序,我使用SQLite数据库,当我向数据库添加一个新项目时,应用程序始终打破我不知道这是什么类型的错误。 任务类:
public class Task {
String name;
String discrb;
int day , month , year ,donecheck ,periocheck;
public Task()
{
donecheck =0;
}
}
SQLite代码:
public class TodoDb extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
private static final String DATABASE_NAME = "todolistdb";
private static final String TABLE_TASKS = "tasks";
private static final String KEY_NAME="Task_Name";
private static final String KEY_DESC ="Description";
private static final String KEY_DAY="Day";
private static final String KEY_MON="Month";
private static final String KEY_YEAR="Year";
private static final String KEY_DONE="Done";
private static final String KEY_PRI="Priority";
public TodoDb(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
String create_table= "Create Table" + TABLE_TASKS + " (" + KEY_NAME +" TEXT PRIMARY KEY ," +
KEY_DESC +" TEXT , " +KEY_DAY +" INTEGER , "+KEY_MON +" INTEGER , "+KEY_YEAR +" INTEGER , "+
KEY_DONE +" INTEGER , "+KEY_PRI +" INTEGER "+ " ) ";
db.execSQL(create_table);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_TASKS);
onCreate(db);
}
// The add task function
public void addTask(Task task)
{
SQLiteDatabase db=this.getWritableDatabase();
ContentValues values=new ContentValues();
values.put(KEY_NAME, task.name);
values.put(KEY_DESC, task.discrb);
values.put(KEY_DAY, task.day);
values.put(KEY_MON, task.month);
values.put(KEY_YEAR, task.year);
values.put(KEY_DONE, task.donecheck);
values.put(KEY_PRI, task.periocheck);
db.insert(TABLE_TASKS,null, values);
db.close();
}
}
那么代码中的错误是什么
答案 0 :(得分:0)
打印时
String create_table= "Create Table" + TABLE_TASKS + " (" + KEY_NAME +" TEXT PRIMARY KEY ," +
KEY_DESC +" TEXT , " +KEY_DAY +" INTEGER , "+KEY_MON +" INTEGER , "+KEY_YEAR +" INTEGER , "+
KEY_DONE +" INTEGER , "+KEY_PRI +" INTEGER "+ " ) ";
Table
之后没有空格,因此创建表语法错误,给出这样的空格
String create_table= "Create Table " + TABLE_TASKS + " (" + KEY_NAME +" TEXT PRIMARY KEY ," +
KEY_DESC +" TEXT , " +KEY_DAY +" INTEGER , "+KEY_MON +" INTEGER , "+KEY_YEAR +" INTEGER , "+
KEY_DONE +" INTEGER , "+KEY_PRI +" INTEGER "+ " ) ";