java - android sqlite no such table -


i'm using premade database , seem getting error when try update row. exact error logcat is: (1) no such table: aud. heres dbhelper class looks like:

public class databasehelper extends sqliteopenhelper { private static string tag = "databasehelper"; // tag logcat window //destination path (location) of our database on device private static string db_path = "/data/data/com.example.simplecurrency3/databases/";  private static string db_name ="currencies";// database name private sqlitedatabase mdatabase;  private final context mcontext;  public databasehelper(context context) { super(context, db_name, null, 2);// 1? database version if(android.os.build.version.sdk_int >= 17){    db_path = context.getapplicationinfo().datadir + "/databases/";          } else {    db_path = "/data/data/" + context.getpackagename() + "/databases/"; } this.mcontext = context; }     public void createdatabase() throws ioexception { //if database not exists copy assets  boolean mdatabaseexist = checkdatabase(); if(!mdatabaseexist) {     this.getreadabledatabase();     this.close();     try      {         //copy database assests         copydatabase();         log.e(tag, "createdatabase database created");     }      catch (ioexception mioexception)      {         throw new error("errorcopyingdatabase");     } } } //check database exists here: /data/data/your package/databases/da name private boolean checkdatabase() {     file dbfile = new file(db_path + db_name);     //log.v("dbfile", dbfile + "   "+ dbfile.exists());     return dbfile.exists(); }  //copy database assets private void copydatabase() throws ioexception {     inputstream minput = mcontext.getassets().open(db_name);     string outfilename = db_path + db_name;     outputstream moutput = new fileoutputstream(outfilename);     byte[] mbuffer = new byte[1024];     int mlength;     while ((mlength = minput.read(mbuffer))>0)     {         moutput.write(mbuffer, 0, mlength);     }     moutput.flush();     moutput.close();     minput.close(); }  //open database, can query public boolean opendatabase() throws sqlexception {     string mpath = db_path + db_name;     //log.v("mpath", mpath);     mdatabase = sqlitedatabase.opendatabase(mpath, null, sqlitedatabase.create_if_necessary);     //mdatabase = sqlitedatabase.opendatabase(mpath, null, sqlitedatabase.no_localized_collators);     return mdatabase != null; }  @override public synchronized void close()  {     if(mdatabase != null)         mdatabase.close();     super.close(); }  @override public void oncreate(sqlitedatabase db) {     // todo auto-generated method stub  }  @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) {     // todo auto-generated method stub  }  } 

and when try update row:

        context context = getactivity().getapplicationcontext();         databasehelper dbhelper = new databasehelper(context);         dbhelper.opendatabase();         sqlitedatabase db = dbhelper.getwritabledatabase();                  db.execsql("update aud set aud = 2.0") 

you have never called createdatabase() method! can put oncreate() method.

good luck


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -