dimanche 12 juillet 2015

SQLite app works on emulator but not in phone

I have an working on a SQLite app and I am new to Android. Everything works fine for me in emulator and when I install in phone unfortunately my app closes. I searched in StackOverflow and googled it, and I find some solutions but nothing worked. Finally I need some help.

My code to getdb from assets is:

private void copyDatabaseFromAssets() {
        // TODO Auto-generated method stub
        InputStream inputStream = null;
        OutputStream outputStream = null;
        String DataBasePath = DATABASE_PATH + DATABASE_NAME;
        try{

            inputStream = context.getAssets().open(DATABASE_NAME);
            outputStream =new FileOutputStream(DataBasePath);
            byte[] buffer = new byte[1024];
            int length;
            while((length =inputStream.read(buffer))>0){
                outputStream.write(buffer, 0, length);
            }
            outputStream.flush();
            outputStream.close();
            inputStream.close();

        }catch(IOException e){
            throw new Error("Problem copying database from resource file");
        }

}

Aucun commentaire:

Enregistrer un commentaire