-1

这是我在 Dbadatper 的 oncreate 方法中创建的表

String CREATE_EXERCISES_TABLE = "CREATE TABLE IF NOT EXISTS " + TABLE_EXERCISES+"("
        + KEY_ROWID + " INTEGER PRIMARY KEY, " 
        + KEY_EXER_NAME + " TEXT, "
        + KEY_DEFAULTMANWEIGHT + " INTEGER, "
        + KEY_DEFAULTWOMANWEIGHT + " INTEGER, "
        + KEY_WEIGHTS_FILT + " INTEGER, "
        + KEY_OLYMPIC_FILT + " INTEGER, "
        + KEY_EQUIPNEED_FILT + " INTEGER, "
        + KEY_UPPERBODY_FILT + " INTEGER, "
        + KEY_LOWERBODY_FILT + " INTEGER, "
        + KEY_LARGEAREA_FILT + " INTEGER);";
db.execSQL(CREATE_EXERCISES_TABLE);

这是我插入练习的插入代码

public void addExercise(Exercise exer) {
    SQLiteDatabase db = this.open();

    ContentValues values = new ContentValues();
    values.put(KEY_EXER_NAME, exer.getName()); 
    values.put(KEY_DEFAULTMANWEIGHT, exer.getDefaultManWeight());
    values.put(KEY_DEFAULTWOMANWEIGHT, exer.getDefaultWomanWeight());
    values.put(KEY_WEIGHTS_FILT, exer.getWeightFilt());
    values.put(KEY_OLYMPIC_FILT, exer.getOlympicFilt()); 
    values.put(KEY_EQUIPNEED_FILT, exer.getEquipFilt()); 
    values.put(KEY_UPPERBODY_FILT, exer.getUpperBodyFilt()); 
    values.put(KEY_LOWERBODY_FILT, exer.getLowerBodyFilt()); 
    values.put(KEY_LARGEAREA_FILT, exer.getLargeAreaFilt()); 

    // Inserting Row
    db.insert(TABLE_EXERCISES, null, values);
    db.close(); // Closing database connection
}

这是我的实际插入

ExerTable db= new ExerTable(ctx);
Exercise pushups =new Exercise("Pushups",0,0,0,0,0,1,0,1);
db.addExercise(pushups);

我已经为此困扰了很长一段时间,每当我尝试运行它时,我都会收到此错误

05-31 19:33:27.107: ERROR/Database(413): Error inserting upperbody_filter=1 olympic_filter=0 default_man_weight=0 default_woman_weight=0 weights_filter=0 lowerbody_filter=0 exername=Pullups large_area_filter=1 equipment_need_filter=1

05-31 19:33:27.107: ERROR/Database(413): android.database.sqlite.SQLiteException: table Exercises has no column named lowerbody_filter: , while compiling: INSERT INTO Exercises(upperbody_filter, olympic_filter, default_man_weight, default_woman_weight, weights_filter, lowerbody_filter, exername, large_area_filter, equipment_need_filter) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?);
4

1 回答 1

1

一切对我来说看起来都不错,所以我最好的猜测是您使用的是实际上没有lowerbody_filter列的旧版本的数据库。如果您在开发早期创建了没有该列的表,并且没有正确设置模式版本号和SQLiteOpenHelper.onUpgrade(),那么您仍将使用旧版本。如果是这种情况,应显示快速卸载/重新安装。如果是这样,那么您的解决方案是确保每次更改架构时始终增加架构版本号,并使用SQLiteOpenHelper.onUpgrade()或其他方式确保在必要时始终升级数据库。

于 2012-06-01T03:05:40.500 回答