0

I have a custom method to
copy the database from assets folder to the database directory

    AssetManager am = myContext.getAssets();
    OutputStream os = new FileOutputStream(DBFile);
    DBFile.createNewFile();
    byte []b = new byte[1024];
    int i, r;
    String []Files = am.list("");
    Arrays.sort(Files);
    for(i=1;i<5;i++)        {
        String fn = String.format("0%d.database", i);
        if(Arrays.binarySearch(Files, fn) < 0)
            break;
        InputStream is = am.open(fn);
        while((r = is.read(b)) != -1)
            os.write(b, 0, r);
        is.close();
    }
    os.close();

All works as expected and the database is copied to the apps database directory except for when I change the android system language (settings>language) and set the system language as arabic, and re install the app, it crashes and the database file isn't copied to the databases directory. It's just a blank file.

Im thinking maybe i should read the database file with an encoding specified because something must change in java dhe moment I change the language.

Ryan
  • 159
  • 2
  • 14
  • "it crashes" -- use LogCat to examine the Java stack trace associated with the crash: https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare Dec 30 '16 at 16:58
  • I know the problem is that function, but it shoes no error. How can I modify the method to show the stack trace? as it shows a sqlite error of no table found as a result of empty database file. – Ryan Dec 30 '16 at 17:05
  • "it shoes no error" -- then how are you determining that "it crashes"? – CommonsWare Dec 30 '16 at 17:06
  • Because as I said, it crashes from the error on the sqlite database It says, error, table not found. And table isn't found because database file is empty. Do you understand? – Ryan Dec 30 '16 at 17:14
  • Is `fn` different? – CL. Dec 30 '16 at 21:34
  • fn is the same. It's the exact same files, for example 01.database and 02.database, I believe It has do do with reading the file specifying utf8 or utf16 encoding, that's my guess but I don't know how to solve it – Ryan Dec 30 '16 at 21:40

0 Answers0