android - SQLite Exception: no such table found -


first of not mark question duplicate. searched every possible options , tried them still isn't working. changed database version, cleared data , reinstalled app well. i've database placed correctly in database folder. still no such table found while compiling error. me figure out i'm lacking in code or i'm doing wrong.

database folder

public class databasehelper extends sqliteopenhelper {       string db_path = null;     private static string db_name = "externaldatabase";     private sqlitedatabase mydatabase;     private final context mycontext;     cursor c =null;      public databasehelper(context context) {         super(context, db_name, null, 11);         this.mycontext = context;         this.db_path = "/data/data/" + context.getpackagename() + "/" + "databases/";         log.e("path 1", db_path);     }      public void createdatabase() throws ioexception {         boolean dbexist = checkdatabase();         if (dbexist) {         } else {             this.getreadabledatabase();             try {                 copydatabase();             } catch (ioexception e) {                 e.tostring();             }         }     }      private boolean checkdatabase() {         sqlitedatabase checkdb = null;         try {             string mypath = db_path + db_name;             checkdb = sqlitedatabase.opendatabase(mypath, null, sqlitedatabase.open_readonly);         } catch (sqliteexception e) {         }         if (checkdb != null) {             checkdb.close();         }         return checkdb != null ? true : false;     }      private void copydatabase() throws ioexception {         inputstream myinput = mycontext.getassets().open(db_name);         string outfilename = db_path + db_name;         outputstream myoutput = new fileoutputstream(outfilename);         byte[] buffer = new byte[10];         int length;         while ((length = myinput.read(buffer)) > 0) {             myoutput.write(buffer, 0, length);         }         myoutput.flush();         myoutput.close();         myinput.close();      }      public void opendatabase() throws sqlexception {         string mypath = db_path + db_name;         mydatabase = sqlitedatabase.opendatabase(mypath, null, sqlitedatabase.open_readonly);      }      @override     public synchronized void close() {         if (mydatabase != null)             mydatabase.close();         super.close();     }       @override     public void oncreate(sqlitedatabase db) {      }      @override     public void onupgrade(sqlitedatabase db, int oldversion, int newversion) {         if (newversion > oldversion)             try {                 copydatabase();             } catch (ioexception e) {                 e.printstacktrace();              }     }        public cursor query(string table, string[] columns, string selection, string[] selectionargs, string groupby, string having, string orderby) {         return mydatabase.query("rates_table", null, null, null, null, null, null);     }       public string getfare(string name, string depart){          sqlitedatabase db = this.getreadabledatabase();           string [] columns = {"rate"};          c = db.rawquery("select rate rates_table place1 = '"+name+"'and place3 = '"+depart+"' or place1 = '"+depart+"'and place3 = '"+name+"'", new string[]{});           stringbuffer buffer = new stringbuffer();         while(c.movetonext()){              string employyename = c.getstring(0);               buffer.append(employyename+"");         }          return buffer.tostring();      } } 

you don't have code in oncreate() method. call createdatabase() method inside oncreate().

@override public void oncreate(sqlitedatabase db) {     createdatabase(); } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -