Java Android:SQLiteDatabase列不存在错误

Java Android:SQLiteDatabase列不存在错误,java,android,database,sqlite,Java,Android,Database,Sqlite,我在为我的程序创建和加载数据库时遇到错误。在编译时,我没有收到这样一个列的错误:responsible: 选择id、名称、责任、优先级 来自任务 有人能指出我做错了什么吗。谢谢 public class TasksSQLiteOpenHelper extends SQLiteOpenHelper { public static final int VERSION = 1; public static final String DB_NAME = "tasks_db.sqlite"; publ

我在为我的程序创建和加载数据库时遇到错误。在编译时,我没有收到这样一个列的错误:responsible: 选择id、名称、责任、优先级 来自任务

有人能指出我做错了什么吗。谢谢

public class TasksSQLiteOpenHelper extends SQLiteOpenHelper {

public static final int VERSION = 1;
public static final String DB_NAME  = "tasks_db.sqlite";
public static final String TASKS_TABLE  = "tasks";
public static final String TASK_ID = "id";
public static final String TASK_NAME = "name";
public static final String TASK_COMPLETE  = "complete";
public static final String TASK_RESPONSIBLE  = "responsible";
public static final String TASK_PRIORITY  = "priority";

public TasksSQLiteOpenHelper(Context context) {
    super(context, DB_NAME, null, VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
    dropAndCreate(db);
}

protected void dropAndCreate(SQLiteDatabase db) {
    db.execSQL("drop table if exists " + TASKS_TABLE + ";");
    createTables(db);
}

protected void createTables(SQLiteDatabase db) {
    db.execSQL(
            "create table " + TASKS_TABLE +" (" +
            TASK_ID + " integer primary key autoincrement not null," +
            TASK_NAME + " text," +
            TASK_COMPLETE + " text," +
            TASK_RESPONSIBLE + " text" +
            TASK_PRIORITY + " integer" +
            ");"
        );
}
}
-

创建表中有一个输入错误


您的代码中有一个小的键入错误。更正版本:

db.execSQL(
    "create table " + TASKS_TABLE +" (" +
    TASK_ID + " integer primary key autoincrement not null," +
    TASK_NAME + " text," +
    TASK_COMPLETE + " text," +
    TASK_RESPONSIBLE + " text," + 
    TASK_PRIORITY + " integer" +
   ");"
 );

糟糕的是,我已经解决了这个问题,但仍然遇到同样的问题。清除应用程序数据并重新启动应用程序。这将导致DDL脚本再次运行,从而再次创建表。仅当SQLite数据库根本不存在时,才调用onCreate,而不是每次打开应用程序时。在修复CREATE表之后,可能需要强制它重新创建数据库。
db.execSQL(
    "create table " + TASKS_TABLE +" (" +
    TASK_ID + " integer primary key autoincrement not null," +
    TASK_NAME + " text," +
    TASK_COMPLETE + " text," +
    TASK_RESPONSIBLE + " text" + // <--- missing a comma
    TASK_PRIORITY + " integer" +
    ");"
);
db.execSQL(
    "create table " + TASKS_TABLE +" (" +
    TASK_ID + " integer primary key autoincrement not null," +
    TASK_NAME + " text," +
    TASK_COMPLETE + " text," +
    TASK_RESPONSIBLE + " text," + 
    TASK_PRIORITY + " integer" +
   ");"
 );