user2411083 user2411083 - 22 days ago 6
Java Question

E/SQLiteLog: (1) table keyTable has no column named number

I keep getting this error:


"table keyTable has no column named number"


Still pretty new to Android, so no clue why this happens, can anyone spot the error?

This is my Database class:

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;
}


This is my class for my table:

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";
}

Answer

Maybe you've edited the DB onCreate but didn't let it re-run? Try uninstalling/install the App, Or update database_version to =2.