-1

プログラムのデータベースの作成とロードでエラーが発生しました。「そのような列はありません:責任:、コンパイル中:SELECT id、name、responsible、priorityFROMtasks」というエラーが表示されます

誰かが私が間違ったことを指摘できますか?ありがとう

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" +
            ");"
        );
}
}

-

public class TaskManagerApplication extends Application {

private SQLiteDatabase database;
private ArrayList<Task> currentTasks;

@Override
public void onCreate() {
    super.onCreate();
    TasksSQLiteOpenHelper helper = new TasksSQLiteOpenHelper(this);
    database = helper.getWritableDatabase();
    if (null == currentTasks) {
        loadTasks();
    }
}

private void loadTasks() {
    currentTasks = new ArrayList<Task>();
    Cursor tasksCursor = database.query(TASKS_TABLE, new String[] {
            TASK_ID, 
            TASK_NAME,
            TASK_RESPONSIBLE,
            TASK_PRIORITY,
            TASK_COMPLETE}, null, null, null, null, String.format("%s,%s", TASK_COMPLETE, TASK_NAME));
    tasksCursor.moveToFirst();
    Task t;
    if (! tasksCursor.isAfterLast()) {
        do {
            int id = tasksCursor.getInt(0);
            String name  = tasksCursor.getString(1);
            String priority  = tasksCursor.getString(2);
            String responsible = tasksCursor.getString(3);
            String boolValue = tasksCursor.getString(4);
            boolean complete = Boolean.parseBoolean(boolValue);
            t = new Task(name, priority, responsible);
            t.setId(id);
            t.setComplete(complete);
            currentTasks.add(t);
        } while (tasksCursor.moveToNext());
    }

    tasksCursor.close();
}
}
4

2 に答える 2

2

;にタイプミスがありますCREATE TABLE

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" +
    ");"
);
于 2012-08-26T16:36:42.643 に答える
0

コードに小さな入力エラーがあります。修正されたバージョン:

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" +
   ");"
 );
于 2012-08-26T16:39:56.770 に答える