I cannot open a Sqlite3
database on my new Android app. In an effort to isolate the problem, I created a brand new app. I placed the sqlite3 db in the Assets
folder under main.
In the manifest, I placed the following lines:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
I have just one activity in this test app, and this is the code in that activity. It does just one thing: attempts to open the db
. It immediately dies and prints out an error to the console (details further below)
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Context context = getApplicationContext();
String db_path = String.valueOf(context.getDatabasePath("production.sqlite3"));
SQLiteDatabase db = SQLiteDatabase.openDatabase(db_path, null, SQLiteDatabase.OPEN_READWRITE);
}
}
Here are the relevant errors from the log:
09-09 20:10:54.788 9850-9850/? E/SQLiteLog: (14) cannot open file at line 31278 of [2ef4f3a5b1]
09-09 20:10:54.788 9850-9850/? E/SQLiteLog: (14) os_unix.c:31278: (2) open(/data/user/0/com.hawthornemackenzie.sesame/databases/production.sqlite3) -
09-09 20:10:54.788 9850-9850/? E/SQLiteDatabase: Failed to open database '/data/user/0/com.hawthornemackenzie.sesame/databases/production.sqlite3'.
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
It seems to be getting a valid path from the getDatabasePath
call but it seems to be saying the file does not exist.