android - using SQLiteAssetHelper -


mydatabase class

import android.content.context; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqlitequerybuilder;  import com.readystatesoftware.sqliteasset.sqliteassethelper;  public class mydatabase extends sqliteassethelper{      private static final string database_name = "databases/mydb.db";     private static final int database_version = 1;      public mydatabase(context context) {         super(context, database_name, null, database_version);     }      public cursor getemployees() {          sqlitedatabase db = getreadabledatabase();         sqlitequerybuilder  qb = new sqlitequerybuilder();          string [] sqlselect = {"_id", "name", "email"};         string sqltables = "contacts";          qb.settables(sqltables);         cursor c = qb.query(db, sqlselect, null, null,                 null, null, null);          c.movetofirst();         return c;      } 

mainactivity class

public class mainactivity extends listactivity {      private cursor employees;     private mydatabase db;      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);          db = new mydatabase(this);         employees = db.getemployees(); // not typically call on main thread          listadapter adapter = new simplecursoradapter(this,                  android.r.layout.simple_list_item_1,                  employees,                  new string[] {"name"},                  new int[] {android.r.id.list});          getlistview().setadapter(adapter);     }      @override     protected void ondestroy() {         super.ondestroy();         employees.close();         db.close();     }  } 

i want connect database in assets folder try example github application stopped working

the logcate : fatal exception: main java.lang.illegalstateexception: not execute method of activity

      caused by: java.lang.illegalargumentexception: file databases/mydb.db contains path separator 

any please thanks

i have got database working did not reference database as

   private static final string database_name = "databases/mydb.db"; 

i access follows:

  private static final string database_name = "mydb.db"; 

i tested way , sure enough breaks it. remove database/ , have mydb.db , should work.


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 -