This is the error i am encountering :
E/SQLiteLog: (1) table contacts has no column named name in "INSERT INTO contacts(phone_number,name) VALUES (?,?)" E/SQLiteDatabase: Error inserting phone_number=22222 name=Name
And here the code running the database which consists of 2 columns, 1 for name and phone number:
public void onCreate(SQLiteDatabase db) {
String create = "CREATE TABLE " + TABLE_CONTACTS + "("+ KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT," + KEY_PH_NO + " TEXT" + ")";
db.execSQL(create2);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS);
onCreate(db);
}
void addContact(Contact c) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_NAME, c.getName());
values.put(KEY_PH_NO, c.getPhoneNumber());
// Inserting Row
db.insert(TABLE_CONTACTS, null, values);
db.close(); // Closing database connection
}
I made sure that the contact class isnt returning null.