android - SQLiteLog error: "No such table" -


this question has answer here:

i got error:

no such table: form

i trying add 3 fields json, json_modified , adminid:

static final string database_name = "db1"; static final int database_version = 2; public static final int name_column = 1;  static final string database_table = "create table " + "adminreg" +         "( " + "adminregid" + " integer primary key autoincrement," + "rest_name text,contact_person_name text,text,password text,address text); "; // variable hold database instance  static final string database_table_reg="create table if not exists " + " form " +         "(" + "id" + " integer primary key autoincrement, " + " json text, adminid text, json_modified text);";  public sqlitedatabase db;  private final context context;  private databasehelper dbhelper; public  logindatabaseadapter(context _context) {     context = _context;     dbhelper = new databasehelper(context, database_name, null, database_version); }  public  logindatabaseadapter open() throws sqlexception {     db = dbhelper.getwritabledatabase();     return this; }  public void close() {     db.close(); }  public  sqlitedatabase getdatabaseinstance() {     return db; }  public void insertentry(string json, string json_modified) {     log.e("data insert reached", "yes");      contentvalues newvalues = new contentvalues();     log.e("json string insert", json);     newvalues.put("json", json);     newvalues.put("json_modified", json_modified);     newvalues.put("adminid", "1");     db.insert("form", null, newvalues);     toast.maketext(context, "data saved", toast.length_long).show();     log.e("context", "toast"); } 

databasehelper.java

public databasehelper(context context, string  name, sqlitedatabase.cursorfactory factory, int version) {     super(context, name, factory, version); }  // called when no database exists in disk , helper class needs // create new one. @override public void oncreate(sqlitedatabase _db) {     _db.execsql(logindatabaseadapter.database_table_reg);     _db.execsql(logindatabaseadapter.database_table); }  // called when there database version mismatch meaning version // of database on disk needs upgraded current version. @override public void onupgrade(sqlitedatabase _db, int _oldversion, int _newversion) {     // log version upgrade.     log.w("taskdbadapter", "upgrading version " + _oldversion + " " + _newversion + ", destroy old data");      // upgrade existing database conform new version. multiple     // previous versions can handled comparing _oldversion , _newversion     // values.     // simplest case drop old table , create new one.     _db.execsql("drop table if exists " + "template");     // create new one.     oncreate(_db); } 

just increase database version or reinstall app.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -