Note that there are some explanatory texts on larger screens.

plurals
  1. POSQLiteOpenHelper problem with fully qualified DB path name
    primarykey
    data
    text
    <p>In my app, I use...</p> <pre><code>myFilesDir = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/" + packageName + "/files"); myFilesDir.mkdirs(); </code></pre> <p>This is fine and the resulting path is...</p> <pre><code>/mnt/sdcard/Android/data/com.mycompany.myApp/files </code></pre> <p>I need a SQLite DB which I want to store on the SD card so I extend SQLiteOpenHelper as follows...</p> <pre><code>public class myDbHelper extends SQLiteOpenHelper { public myDbHelper(Context context, String name, CursorFactory factory, int version) { // NOTE I prefix the full path of my files directory to 'name' super(context, myFilesDir + "/" + name, factory, version); } @Override public void onCreate(SQLiteDatabase db) { // Create tables and populate with default data... } } </code></pre> <p>So far so good - the first time I call <code>getReadableDatabase()</code> or <code>getWriteableDatabase()</code> the empty DB is created on the SD card and <code>onCreate()</code> populates it.</p> <p>So here's the problem - the app is in beta testing with maybe 5 or 6 people and, like me, they're running Android v2.2 and everything works fine. I have one tester, however, running v2.1 and when <code>myDbHelper</code> tries to create the DB on first use, it crashes with the following...</p> <pre><code>E/AndroidRuntime( 3941): Caused by: java.lang.IllegalArgumentException: File /nand/Android/data/com.mycompany.myApp/files/myApp-DB.db3 contains a path separator E/AndroidRuntime( 3941): at android.app.ApplicationContext.makeFilename(ApplicationContext.java:1445) E/AndroidRuntime( 3941): at android.app.ApplicationContext.openOrCreateDatabase(ApplicationContext.java:473) E/AndroidRuntime( 3941): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:193) E/AndroidRuntime( 3941): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:98) E/AndroidRuntime( 3941): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:158) </code></pre> <p>The path for the files directory is an odd one ("/nand") as it's internal memory although not the phone's own internal memory - but it is the path returned by <code>getExternalStorageDirectory()</code> for this device.</p> <p>I can see three possible answers...</p> <ol> <li>Although acceptable on v2.2, specifying a fully qualified path for DB name isn't recommended and will fail on earlier versions</li> <li>Fully qualified paths are acceptable for SD card storage but the "/nand" path is being interpreted as 'internal' and only relative paths are acceptable in this case</li> <li>Something else which I'm missing completely</li> </ol> <p>If any or all of the above apply I'd appreciate it if somebody could help with how I should approach this.</p> <p>Thanks.</p>
    singulars
    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.
 

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