データベースにレコードを挿入しようとしていますが、エラーが発生します。私が得ていない問題は何ですか。IMAGEPATH列を削除して同じコードを試しましたが、DESCRIPTIONに対して同じエラーが発生します。
DataBaseHelper:
public class GREDatabaseHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "gre_db.db";
private static final int DATABASE_VERSION = 1;
public static final String TABLE_NAME_ENGLISH = "english_table";
public static final String COLUMN_NAME_WORD = "word_column";
public static final String COLUMN_NAME_SYNONYM = "synonym_column";
public static final String COLUMN_NAME_DESCRIPTION = "descrption_column";
public static final String COLUMN_NAME_IMAGEPATH = "image_column";
GREDatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String sqlQueryToCreateEnglishTable = "CREATE TABLE IF NOT EXISTS "
+ TABLE_NAME_ENGLISH + " (" + COLUMN_NAME_WORD
+ "TEXT PRIMARY KEY, " + COLUMN_NAME_SYNONYM + "TEXT, "
+ COLUMN_NAME_DESCRIPTION + "TEXT, " + COLUMN_NAME_IMAGEPATH
+ "TEXT " + ");";
db.execSQL(sqlQueryToCreateEnglishTable);
Log.d("Table_Created", "english_table");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
@Override
public void onOpen(SQLiteDatabase db) {
super.onOpen(db);
}
void addWord(EngFieldsClass obj) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(COLUMN_NAME_WORD, obj.getengWord());
cv.put(COLUMN_NAME_SYNONYM, obj.getengSynonyms());
cv.put(COLUMN_NAME_DESCRIPTION, obj.getengDescription());
cv.put(COLUMN_NAME_IMAGEPATH, obj.getengImage());
// INSERT ROWS
db.insertOrThrow(TABLE_NAME_ENGLISH, null, cv);
db.close();
}
}
InsertRecordクエリ:
String word=editTextWord.getText().toString();
String synonym= editText Synonym.getText().toString();
String description= editText Description.getText().toString();
String imgpath=textViewImagePath.getText().toString();
final GREDatabaseHelper db= new GREDatabaseHelper(this);
db.addWord(new EngFieldsClass(word,synonym,description,imgpath));
エラー:
08-26 19:03:36.230: D/Table_Created(1350): english_table
08-26 19:03:36.239: I/Database(1350): sqlite returned: error code = 1, msg = table english_table has no column named image_column
08-26 19:03:36.249: D/AndroidRuntime(1350): Shutting down VM
08-26 19:03:36.259: W/dalvikvm(1350): threadid=1: thread exiting with uncaught exception (group=0x40015560)
08-26 19:03:36.269: E/AndroidRuntime(1350): FATAL EXCEPTION: main
08-26 19:03:36.269: E/AndroidRuntime(1350): android.database.sqlite.SQLiteException: table english_table has no column named image_column: , while compiling: INSERT INTO english_table(image_column, descrption_column, synonym_column, word_column) VALUES(?, ?, ?, ?);