android - Table has no column named xyz while inserting data into SQLite database -
it says column name bmi not exist. resulting error message system cannot find column called bmi. checked couple of times , couldn't find mistake in code. maybe guys see one... full stack dump attached after code.
public class mydbhandler extends sqliteopenhelper{ private static final int database_version = 1; private static final string database_name = "bmiwerte.db"; public static final string table_bmis = "bmis"; public static final string column_id = "_id"; public static final string column_name = "name"; public static final string column_bmi = "bmi"; public mydbhandler(context context, string name, sqlitedatabase.cursorfactory factory, int version) { super(context, database_name, factory, database_version); } private static final string create_table_bmis = "create table " +table_bmis +" (" +column_id +" integer autoincrement, " +column_name +" text primary key" +column_bmi +" text" +");"; @override public void oncreate(sqlitedatabase db) { //lässt query in sql laufen log.i("exxxx", "creating check"); db.execsql(create_table_bmis); } @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { db.execsql("drop table if exist " + table_bmis); oncreate(db); } public void addvalues(bmi_werte wert){ contentvalues values = new contentvalues(); values.put(column_name, wert.get_name()); values.put(column_bmi, wert.get_bmiwert().tostring()); log.i("exxx", wert.get_name()); log.i("exxxx", wert.get_bmiwert().tostring()); sqlitedatabase db = getwritabledatabase(); db.insert(table_bmis, null, values); db.close(); } public void deletevalues(string name){ log.i("exxxx", "deletevaluse"); sqlitedatabase db = getwritabledatabase(); db.execsql("delete " + table_bmis + " " + column_name + "=\"" + name + "\";"); } public string databasetostring(){ string dbstring = ""; sqlitedatabase db = this.getwritabledatabase(); string query = "select * " + table_bmis; string test = "describe " + table_bmis; cursor c = db.rawquery(query, null); c.movetofirst(); while(!c.isafterlast()){ if(c.getstring(c.getcolumnindex("name")) != null){ dbstring += c.getstring(c.getcolumnindex("name")); dbstring += "\n"; } c.movetonext(); } db.close(); return dbstring; }
}
error , stack dump:
its typo, forget ,
while creating table
+column_name +" text primary key, " // add , after primary key +column_bmi
uninstall application emulator/device , install again resolve it.
Comments
Post a Comment