Note that there are some explanatory texts on larger screens.

plurals
  1. POCopy Database in assets to data/database work in emulator but not work in device
    primarykey
    data
    text
    <p>i have this code: Working in emulator but fail in devices. i want copy the database stored in assets to data/data/.... when load app apears "Error File" (FileNotFoundException e) -> error</p> <pre><code>public void copiarDB() { try { String destPath = "/data/data/" + getPackageName() + "/databases/MiBD"; File f = new File(destPath); if (!f.exists()) { CopyDB(getBaseContext().getAssets().open("datosejer"), new FileOutputStream(destPath)); } } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(MainActivity.this, "Error File", Toast.LENGTH_SHORT) .show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(MainActivity.this, "Error IO", Toast.LENGTH_SHORT) .show(); } AdaptadorBD db = new AdaptadorBD(this); // ---obtener todos los contactos--- db.abrir(); Cursor c = db.obtenerTodosLosDatosEjercicio(); if (c.moveToFirst()) { do { // DisplayContact(c); } while (c.moveToNext()); } db.cerrar(); } public void CopyDB(InputStream inputStream, OutputStream outputStream) throws IOException { // ---copy 1K bytes at a time--- byte[] buffer = new byte[1024]; int length; while ((length = inputStream.read(buffer)) &gt; 0) { outputStream.write(buffer, 0, length); } inputStream.close(); outputStream.close(); Toast.makeText(MainActivity.this, "Se ha copiado la Base de datos", Toast.LENGTH_SHORT).show(); } </code></pre> <p>I run in emulator and work perfectly, but in my devices dont work, the OS of emulator is 4.3 and OS of my devices is 4.0.4(rooted),4.0.4 and 4.3. </p> <p>one line of DB is:</p> <blockquote> <p>14 11107 Ovalo con mancuernas 11 Hombros 3 12 10 No hay datos Utiliza inicialmente las mancuernas con menor peso que encuentres en tu gimnasio para que aprendas el movimiento y a dominar el peso. Trabajarás la región anterior del hombro. img11107_1.png img11107_2.png img11107_3.png</p> </blockquote> <p><strong>UPDATED:</strong></p> <p>I put the solution in the next comment.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload