Note that there are some explanatory texts on larger screens.

plurals
  1. POFile not found Exception when trying to open android SQLite database
    primarykey
    data
    text
    <p>I have the following code as a DataBaseHelper in an android aplication:</p> <pre><code> public class DbUtils { private static final String DB_PATH = "/data/data/com.project.skcompanion/databases/"; private static final String DB_NAME = "basesh.sqlite"; public static void createDatabaseIfNotExists(Context context) throws IOException { Log.d("check1", "check1"); boolean createDb = false; File dbDir = new File(DB_PATH); File dbFile = new File(DB_PATH + DB_NAME); if (!dbDir.exists()) { dbDir.mkdir(); createDb = true; } else if (!dbFile.exists()) { createDb = true; } else { // Check that we have the latest version of the db boolean doUpgrade = false; if (doUpgrade) { dbFile.delete(); createDb = true; } } Log.d("check2", "check2"); if (createDb) { Log.d("check3", "check3"); // Open your local db AssetManager am = context.getAssets(); InputStream myInput = am.open(DB_NAME); Log.d("check4", "check4"); // Open the empty db OutputStream myOutput = new FileOutputStream(dbFile); // transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer)) &gt; 0) { myOutput.write(buffer, 0, length); } // Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } } public static SQLiteDatabase getStaticDb() { return SQLiteDatabase.openDatabase(DB_PATH + DB_NAME, null, SQLiteDatabase.NO_LOCALIZED_COLLATORS); } </code></pre> <p>But when the code tries to open the basesh.sqlite it sends a FileNotFoundException. I have my basesh.sqlite file in assets/databases. After some debugging, i think the problem is in this line.</p> <pre><code>InputStream myInput = am.open(DB_NAME); </code></pre> <p>But i have no idea why it isn't opening my file. Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
 

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