android - E/SQLiteLog(1893): (14) cannot open file at line 30176 of [00bb9c9ce4] -


i using this tutorial import database app.

it runs fine on api 10,

but on api 17 throws following error:

05-19 14:52:46.492: e/sqlitelog(1893): (14) cannot open file @ line 30176 of [00bb9c9ce4] 05-19 14:52:46.492: e/sqlitelog(1893): (14) os_unix.c:30176: (2) open(/data/data/com.example.koday/databases/dizionario7.sqlite) -  05-19 14:52:46.492: e/sqlitedatabase(1893): failed open database '/data/data/com.example.koday/databases/dizionario7.sqlite'. 05-19 14:52:46.492: e/sqlitedatabase(1893): android.database.sqlite.sqlitecantopendatabaseexception: unknown error (code 14): not open database 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ android.database.sqlite.sqliteconnection.nativeopen(native method) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ android.database.sqlite.sqliteconnection.open(sqliteconnection.java:209) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ android.database.sqlite.sqliteconnection.open(sqliteconnection.java:193) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ android.database.sqlite.sqliteconnectionpool.openconnectionlocked(sqliteconnectionpool.java:463) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ android.database.sqlite.sqliteconnectionpool.open(sqliteconnectionpool.java:185) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ android.database.sqlite.sqliteconnectionpool.open(sqliteconnectionpool.java:177) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ android.database.sqlite.sqlitedatabase.openinner(sqlitedatabase.java:804) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ android.database.sqlite.sqlitedatabase.open(sqlitedatabase.java:789) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ android.database.sqlite.sqlitedatabase.opendatabase(sqlitedatabase.java:694) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ android.database.sqlite.sqlitedatabase.opendatabase(sqlitedatabase.java:669) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ com.example.koday.databasehelper.checkdatabase(databasehelper.java:82) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ com.example.koday.databasehelper.createdatabase(databasehelper.java:45) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ com.example.koday.mainactivity.frontquiz(mainactivity.java:70) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ com.example.koday.mainactivity.oncreate(mainactivity.java:64) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ android.app.activity.performcreate(activity.java:5104) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1080) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ android.app.activitythread.performlaunchactivity(activitythread.java:2144) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ android.app.activitythread.access$600(activitythread.java:141) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ android.app.activitythread$h.handlemessage(activitythread.java:1234) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ android.os.handler.dispatchmessage(handler.java:99) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ android.os.looper.loop(looper.java:137) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ android.app.activitythread.main(activitythread.java:5039) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ java.lang.reflect.method.invokenative(native method) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ java.lang.reflect.method.invoke(method.java:511) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 05-19 14:52:46.492: e/sqlitedatabase(1893):     @ dalvik.system.nativestart.main(native method) 05-19 14:52:47.683: e/(1893): database aperto 05-19 14:52:47.683: e/sqlitelog(1893): (1) no such table: dati 

here code:

public class databasehelper extends sqliteopenhelper {  // android's default system path of application database. private static string db_path = "/data/data/com.example.koday/databases/";  private static string db_name = "dizionario7.sqlite";  private sqlitedatabase mydatabase;  private final context mycontext;  /**  * constructor takes , keeps reference of passed context in order  * access application assets , resources.  *   * @param context  */ public databasehelper(context context) {      super(context, db_name, null, 1);     this.mycontext = context; }  /**  * creates empty database on system , rewrites own  * database.  * */ public void createdatabase() throws ioexception {      boolean dbexist = checkdatabase();      if (dbexist) {         // nothing - database exist     } else {          // calling method , empty database created         // default system path         // of application gonna able overwrite         // database our database.         this.getreadabledatabase();          try {              copydatabase();          } catch (ioexception e) {              throw new error("error copying database");          }     }  }  /**  * check if database exist avoid re-copying file each  * time open application.  *   * @return true if exists, false if doesn't  */ private boolean checkdatabase() {      sqlitedatabase checkdb = null;      try {         string mypath = db_path + db_name;         checkdb = sqlitedatabase.opendatabase(mypath, null,                 sqlitedatabase.open_readonly);      } catch (sqliteexception e) {          // database does't exist yet.      }      if (checkdb != null) {          checkdb.close();      }      return checkdb != null ? true : false; }  /**  * copies database local assets-folder created  * empty database in system folder, can accessed ,  * handled. done transfering bytestream.  * */ private void copydatabase() throws ioexception {      // open local db input stream     inputstream myinput = mycontext.getassets().open(db_name);      // path created empty db     string outfilename = db_path + db_name;      // open empty db output stream     outputstream myoutput = new fileoutputstream(outfilename);      // transfer bytes inputfile outputfile     byte[] buffer = new byte[1024];     int length;     while ((length = myinput.read(buffer)) > 0) {         myoutput.write(buffer, 0, length);     }      // close streams     myoutput.flush();     myoutput.close();     myinput.close();  }  public void opendatabase() throws sqlexception {      // open database     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) {  }  // add public helper methods access , content // database. // return cursors doing "return mydatabase.query(....)" it'd // easy // create adapters views.  // getting single contact string getkword(string word) {     sqlitedatabase db = this.getreadabledatabase();      cursor cursor = db.query("data",             new string[] { "_id", "english", "korean" }, "english" + "=?",             new string[] { word }, null, null, null, null);     if (cursor != null)         cursor.movetofirst();      string kword = cursor.getstring(2);     // return contact     db.close();     return kword;  }  // getting contacts public cursor getcursor() {     // select query     string selectquery = "select  * " + "data";      sqlitedatabase db = this.getwritabledatabase();     cursor cursor = db.rawquery(selectquery, null);      // looping through rows , adding list      return cursor; }  } 

edit edit edit edit have set permission in manifest:

<uses-permission android:name="android.permission.write_external_storage"/> 

thanks help!

i think problem location of db different version of sdk. please try this

private static string db_path = ""; public databasehelper(context context) {     super(context, db_name, null, 1);// 1? database version     if(android.os.build.version.sdk_int >= 4.2){         db_path = context.getapplicationinfo().datadir + "/databases/";              } else {        db_path = "/data/data/" + context.getpackagename() + "/databases/";     }     this.mcontext = context;  }   

check out

how use existing database android application


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -