我的代码
myDb = openOrCreateDatabase("/sdcard/FashionGirl/ImagesDB.db", Context.MODE_PRIVATE, null);
myDb = openOrCreateDatabase(dbPath, Context.MODE_PRIVATE, null);
工作完美,但发出警告Do not hardcode "/sdcard/"; use Environment.getExternalStorageDirectory().getPath() instead
所以我尝试了,
String dbPath = Environment.getExternalStorageDirectory().getAbsolutePath() + "FashionGirl/ImagesDB.db";
myDb = openOrCreateDatabase(dbPath, Context.MODE_PRIVATE, null);
但奇怪的是,它不起作用,其中 Environment.getExternalStorageDirectory().getAbsolutePath() 具有价值/storage
所以它给出错误,
12-17 19:32:02.230: E/SqliteDatabaseCpp(15620): sqlite3_open_v2("/storageFashionGirl/ImagesDB.db", &handle, 6, NULL) failed
12-17 19:32:02.230: E/SQLiteDatabase(15620): Failed to open the database. closing it.
12-17 19:32:02.230: E/SQLiteDatabase(15620): android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file
12-17 19:32:02.230: E/SQLiteDatabase(15620): at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
12-17 19:32:02.230: E/SQLiteDatabase(15620): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:983)
12-17 19:32:02.230: E/SQLiteDatabase(15620): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:956)
12-17 19:32:02.230: E/SQLiteDatabase(15620): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:932)
那么为什么Android推荐的东西不起作用,我该怎么办?