I’m trying to create a database file in other location, but the app always failed to do so.
try {
File sdcardfile = Environment.getExternalStorageDirectory();
SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(sdcardfile.getPath()+ "/test.db", null);
System.out.println("Its open? " + db.isOpen());
} catch (Exception e) {
tv.setText("error is "+e.toString());// tv is a text view
}
I can create any database, as long as it doesn’t use altered path.
It work fine if I use “test.db”, but not if I use “//test.db”.
This is the logcat text:
01-21 20:14:19.470: I/Database(3678): sqlite returned: error code = 14, msg = cannot open file at source line 25467
The Error it throws me is : SQLite exception: unable to open database file.
I use BlueStack as my emulator.
Thank you all for reading.
Edited: my apps fails because it lacks WRITE PERMISSION… insert it and everything’s ok.
Wild guessing (information missing in your question), but did you request permission to access the SD card in your app’s manifest?
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />