java - can't insert into sqlite database, error: Table doen't exist -



java - can't insert into sqlite database, error: Table doen't exist -

i have been trying solve seems simple problem lastly 3 days, trying insert record sqlite database activity, have searched issue without look. below find activity code , dbhelper code. dbhelper code:

public long insertresult(string quest_id,string test1,string test2) { sqlitedatabase db = this.getwritabledatabase(); contentvalues initialvalues = new contentvalues(); initialvalues.put("question", quest_id); initialvalues.put("rights", test1); initialvalues.put("wrongs", test2); log.d("result:", "rights " + initialvalues.get("rights")); homecoming db.insertorthrow("results", null, initialvalues); } mainactivity long ins = mydbhelper.insertresult("test","test2","test3");

results table doesn't exist in database.

it looks dbhelper extending sqliteopenhelper. should override oncreate method in dbhelper. example, add together this:

@override public void oncreate(sqlitedatabase db) { db.execsql("create table results (_id integer primary key autoincrement, question text not null, rights text not null, wrongs text not null);"); }

if ever alter database schema you'll need override onupgrade method.

java android sqlite android-studio

Comments

Popular posts from this blog

Using Android Volley to post an array to PHP -

python - How to add an model instance to a django queryset? -

angularjs - No 'Access-Control-Allow-Origin' error from local domain to public API -