我创建了一个这样的数据库当我尝试在其中添加一个注释时,我收到一个错误,表示没有列名为title的列。
private static final String TABLE_NOTES = "notes";
private static final String KEY_ID = "id";
private static final String KEY_DATE_TIME = "time";
private static final String KEY_CHIELD_OF = "chield_of";
private static final String KEY_TITLE = "title";
private static final String KEY_NOTE = "note";
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_NOTES_TABLE = "CREATE TABLE " + TABLE_NOTES + "("
+ KEY_ID + " INTEGER PRIMARY KEY,"
+ KEY_DATE_TIME + " INTEGER,"
+ KEY_CHIELD_OF + " TEXT,"
+ KEY_TITLE + " TEXT,"
+ KEY_NOTE + " TEXT" + ")";
db.execSQL(CREATE_NOTES_TABLE);
}
void addNotes(Notes note) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_CHIELD_OF, note.getChieldOf());
values.put(KEY_TITLE, note.getTitle());
values.put(KEY_NOTE, note.getNote());
db.insert(TABLE_NOTES, null, values);
db.close(); // Closing database connection
}
我的错误在哪里?
答案 0 :(得分:0)
如果您已经在设备或模拟器上安装了应用程序并且向表中添加了新列,则不会调用onCreate
方法(仅在安装数据库时调用该方法)。
请卸载您的应用并重新安装。