我不断收到此错误:
“表 keyTable 没有名为 number 的列”
对 Android 来说还是很新,所以不知道为什么会发生这种情况,有人能发现错误吗?
这是我的数据库类:
public class KeyDatabase extends SQLiteOpenHelper {
private static final String database_name = "KeyDatabase.db";
private static final int database_version = 1;
KeyDatabase (Context context){
super(context,database_name,null,database_version);
}
@Override
public void onCreate (SQLiteDatabase db){
db.execSQL("CREATE TABLE " + KeyTableClass.table_name
+ "(" + KeyTableClass.id + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ KeyTableClass.number + " TEXT, "
+ KeyTableClass.key + " TEXT);");
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
db.execSQL("DROP TABLE IF EXISTS " + KeyTableClass.table_name);
onCreate(db);
}
public long InsertKey (String number, String key){
ContentValues valuesToInsert = new ContentValues();
valuesToInsert.put(KeyTableClass.number, number);
valuesToInsert.put(KeyTableClass.key, key);
SQLiteDatabase sd = getWritableDatabase();
long result = sd.insert(KeyTableClass.table_name, KeyTableClass.number, valuesToInsert);
return result;
}
这是我的桌子课:
public class KeyTableClass {
//The name of the table
public static final String table_name = "keyTable";
//The columns of the table
public static String id = "id";
public static String number = "number";
public static String key = "key";
}