私のアプリケーションは単純なテーブルを作成できません。以下のコードをご覧ください。
DatabaseHandler.java
public class DatabaseHandler extends SQLiteOpenHelper {
private static final int DB_VERSION = 1;
private static final String DB_NAME = "PASSENGER_INFO_DB";
private static final String TABLE_NAME = "PASSENGER_INFO";
private static final String TABLE_COLUMN_SEAT_NO = "SEAT_NO";
private static final String TABLE_COLUMN_NAME = "NAME";
private static final String TABLE_COLUMN_AGE = "AGE";
private static final String TABLE_COLUMN_GENDER = "GENDER";
private static final String TABLE_COLUMN_FOOD_PREF = "FOOD_PREF";
private static final String CREATE_PASSENGER_INFO_TABLE = "CREATE TABLE IF NOT EXISTS "
+ TABLE_NAME + " ( " + TABLE_COLUMN_SEAT_NO
+ " TEXT PRIMARY KEY, " + TABLE_COLUMN_NAME + " TEXT, "
+ TABLE_COLUMN_AGE + " INTEGER, " + TABLE_COLUMN_GENDER
+ " INTEGER, " + TABLE_COLUMN_FOOD_PREF + " TEXT" + ")";
public DatabaseHandler(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_PASSENGER_INFO_TABLE);
}
public void addPassengerInfo(PassengerInfo passInfo) {
SQLiteDatabase addPass = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(TABLE_COLUMN_SEAT_NO, passInfo.getM_seatNo());
values.put(TABLE_COLUMN_NAME, passInfo.getM_name());
values.put(TABLE_COLUMN_AGE, passInfo.getM_age());
values.put(TABLE_COLUMN_GENDER, passInfo.getM_gender());
values.put(TABLE_COLUMN_FOOD_PREF, passInfo.getM_foodPref());
addPass.insert(TABLE_NAME, null, values);
addPass.close();
}
MainActivity.javaで
DatabaseHandler dbhandler = new DatabaseHandler(this);
addSeat = "1A";
passName = "NA";
passAge = 0;
passGender = -1;
passFoodPref = "NA";
dbhandler.addPassengerInfo(new PassengerInfo(addSeat, passName, passAge, passGender, passFoodPref));
(PassengerInfo.classには、フィールド用のgetterメソッドとsetterメソッドがあります)
これを実行すると、logcatで次のエラーが発生します。
01-23 19:09:18.311: I/Database(1303): sqlite returned: error code = 1, msg = table PASSENGER_INFO has no column named SEAT_NO
01-23 19:09:18.370: E/Database(1303): Error inserting FOOD_PREF=NA NAME=NA AGE=0 GENDER=-1 SEAT_NO=1A
また、adbシェルを介してデータベースに作成されたテーブルを確認しました。PASSENGER_INFOという名前のテーブルはありません。助けてください !