samedi 17 octobre 2015

Android error when accesing sqlite

I have an app published which has a sqlite database, but I'm receiving this error from some users (more than 99% of the users don't get the error) but one or two each day send me this trace:

java.lang.Error: /data/data/(PACKAGENAME)/databases/(FILENAME).sqlite: open failed: ENOENT (No such file or directory)

This is my code:

private void copyDataBase() throws IOException {
  InputStream myInput = myContext.getAssets().open(DB_NAME+".sqlite");
  String outFileName = Environment.getDataDirectory() + "/data/"+context.getPackageName()+"/databases/"+ DB_NAME+".sqlite";
  OutputStream myOutput = new FileOutputStream(outFileName);
  byte[] buffer = new byte[1024];
  int length;
  while ((length = myInput.read(buffer))>0){
       myOutput.write(buffer, 0, length);
  }
  myOutput.flush();
  myOutput.close();
  myInput.close();
}

I'm confused because it works with every smartphone, but on some of them it is not working correctly :(

Aucun commentaire:

Enregistrer un commentaire