SQLite returned an error code of 14
I had the same problem.
What solved it, was replacing
private static String DB_PATH = "/data/data/YOUR_PACKAGE/databases/";
with
String myPath = myContext.getFilesDir().getAbsolutePath().replace("files",
"databases")+File.separator + DB_NAME;
Today this issue cost me 3 hours. What I tried:
- Rewriting the copy database code.
- Deleting the app from the emulator / device
- Wiping emulator(s)
- Cleaning eclipse
- Changing file permissions
I solved the problem by copying the code from a shared Dropbox account to another location and refactoring the code in the Android Manifest and java files with another package name.
The application runs beautifully now.
I have seen this error occur if you are using sharedUserId in your manifest. If you change the sharedUserId of an application and reinstall the application it does not have the required ownership to write to the SQLite database.
This may be a little late, but hope this helps for whoever gets this problem (since I can't find a definitive solution around).
I think I know the reason for this cause (at least for my case). Looking in the DDMS --> File Explorer, you'd realize that the Database Folder (/data/data//databases/) does not exist, which is why the application cannot create the database file in that non-existent folder. If you can create a databases folder in some manner, you can avoid this problem.
Because I'm lazy, I just used the /data/data//files/ folder when I'm in Emulator mode. You can get the files dir using this:
context.getFilesDir().getPath()
This worked beautifully for me in the Emulator.
Hope this helps someone.
In case you want to see some code:
String dbFilename = "example.db";
try
{
File databaseFile = getDatabasePath(dbFilename);
SQLiteDatabase _db = SQLiteDatabase.openOrCreateDatabase(databaseFile);
} catch (Exception e)
{
String databasePath = getFilesDir().getPath() + "/" + dbFilename;
File databaseFile = new File(databasePath);
_db = SQLiteDatabase.openOrCreateDatabase(databaseFile);
}
EDIT: I tried logging into Facebook (my app has FB integration) on the Emulator and /databases folder appeared after that (and persisted). Not sure what happened, but it's possible to create that folder somehow. Something for another expert around here to shed light on.