Reputation: 1858
I am trying to export an sqlite database to the sdcard. When I test the application (both on real device and on emulator) I get an error regarding the path of my database. When I check from the DDMS the path of the database it seems to be the one that is printed as not found.
File dbFile =
new File(Environment.getDataDirectory() + "/data/"+c.getPackageName()+"/databases/myDB.db");
AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
I used the code found here: Making a database backup to SDCard on Android
Upvotes: 3
Views: 1948
Reputation: 48871
Firstly, don't use hardcoded paths for anything in Android - they're not guaranteed to be the same across all devices.
Try using getDatabasePath("myDB.db").getAbsolutePath();
Upvotes: 1
Reputation: 2049
This problem is commonly caused by incorrectly starting an activity. Activities (except the first) have to be called by intents. Starting an activity using something like
Activity a = new ActivityExample();
will cause this error to be thrown on all file system access calls
Upvotes: 0