android - Unable to access preloaded SQLite database file -


i using pre loaded sqlite database android app. working fine when test on emulator. when try on real device, returns error saying:

android.database.sqlite.sqliteexception: no such table: supplier

i have checked database file , has table 'supplier'.

i believe have placed .db file in correct location (initially misspelled , got errors db not found. fixed , error gone since).

using following code , dependency. have attached screen shot database located now. please advice.

dependencies {         compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+' } 

.

string tablename = "supplier"; @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      //getting database stored in assets folder     try {         dbhelper dbhelper = new dbhelper(this);         dbhelper.getreadabledatabase();         } catch (sqliteassethelper.sqliteassetexception e) {             e.printstacktrace();         }     }  public void sqltest(view v){     sqlitedatabase db = this.openorcreatedatabase("quotedb", mode_private, null);     string[] inserts = {category, preferences.getstring(category, "1")};     //this line throws table name not found error     cursor c = db.rawquery("select quote " +  tablename + " category=? , rowid=? limit 1", inserts); }  private class dbhelper extends sqliteassethelper{     private static final string database_name = "quotedb.db";     private static final int database_version = 1;      public dbhelper(context context) {         super(context, database_name, null, database_version);     } } 

enter image description here

on whole, if using sqliteassethelper (or sqliteopenhelper), use consistently. don't mix , match using helper , accessing database separately (e.g., via openorcreatedatabase()). in part, because want there one instance of sqlitedatabase database @ time, shared threads, synchronization purposes. that's easiest if have 1 consistent spot of getting sqlitedatabase, , if you're using helper, helper should consistent spot. typically, helper turns singleton or wrapped in contentprovider, can everywhere that's needed.

that being said, can't quite explain former symptoms, have expected work. though, since use openorcreatedatabase() approximately once year, don't have ton of experience specific scenario.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -