android 是否有某种限制,你可以一次创建多少个目录?因为我实际上是在尝试将我的数据库保存在子子目录中。所以我正在使用以下代码..
DATABASE_NAME = Environment.getExternalStorageDirectory() + "/AllDatabases/" + comp
+ "/Balance/" + wy + ".db";
当我首先创建一个名为“AllDatabases”的文件夹,然后在其中创建一个带有变量“comp”的特定值的子文件夹(比如“lol”)时,代码工作得非常好
where comp = lol
然后它在那里成功地创建了数据库。但是当我再次删除创建的文件夹并直接尝试使用上面的语句构建它时,我正在为我的 DATABASE_NAME 分配一些值,它会强制关闭我的应用程序。这就是 LogCat 显示的...
01-21 18:03:30.194: E/Database(19098): sqlite3_open_v2("/mnt/sdcard/lol/MyLedgers/2012-2013.db", &handle, 6, NULL) failed
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): Couldn't open /mnt/sdcard/lol/MyLedgers/2012-2013.db for writing (will try read-only):
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): android.database.sqlite.SQLiteException: unable to open database file
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1921)
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:883)
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:960)
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:953)
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:548)
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:98)
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:158)
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): at com.balance.start.LedgerInfoDB.opentoread(LedgerInfoDB.java:78)
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): at com.balance.start.MainView.onCreate(MainView.java:101)
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2633)
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2685)
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): at android.app.ActivityThread.access$2300(ActivityThread.java:126)
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2038)
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): at android.os.Handler.dispatchMessage(Handler.java:99)
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): at android.os.Looper.loop(Looper.java:123)
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): at android.app.ActivityThread.main(ActivityThread.java:4633)
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): at java.lang.reflect.Method.invokeNative(Native Method)
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): at java.lang.reflect.Method.invoke(Method.java:521)
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
01-21 18:03:30.254: E/SQLiteOpenHelper(19098): at dalvik.system.NativeStart.main(Native Method)
01-21 18:03:30.254: E/Database(19098): sqlite3_open_v2("/mnt/sdcard/chomu/MyLedgers/2012-2013.db", &handle, 1, NULL) failed
01-21 18:03:30.264: W/dalvikvm(19098): threadid=1: thread exiting with uncaught exception (group=0x400207d8)
01-21 18:03:30.264: E/AndroidRuntime(19098): FATAL EXCEPTION: main
01-21 18:03:30.264: E/AndroidRuntime(19098): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.balance.start/com.balance.start.MainView}: android.database.sqlite.SQLiteException: unable to open database file
01-21 18:03:30.264: E/AndroidRuntime(19098): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
01-21 18:03:30.264: E/AndroidRuntime(19098): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2685)
01-21 18:03:30.264: E/AndroidRuntime(19098): at android.app.ActivityThread.access$2300(ActivityThread.java:126)
01-21 18:03:30.264: E/AndroidRuntime(19098): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2038)
01-21 18:03:30.264: E/AndroidRuntime(19098): at android.os.Handler.dispatchMessage(Handler.java:99)
01-21 18:03:30.264: E/AndroidRuntime(19098): at android.os.Looper.loop(Looper.java:123)
01-21 18:03:30.264: E/AndroidRuntime(19098): at android.app.ActivityThread.main(ActivityThread.java:4633)
01-21 18:03:30.264: E/AndroidRuntime(19098): at java.lang.reflect.Method.invokeNative(Native Method)
01-21 18:03:30.264: E/AndroidRuntime(19098): at java.lang.reflect.Method.invoke(Method.java:521)
01-21 18:03:30.264: E/AndroidRuntime(19098): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
01-21 18:03:30.264: E/AndroidRuntime(19098): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
01-21 18:03:30.264: E/AndroidRuntime(19098): at dalvik.system.NativeStart.main(Native Method)
01-21 18:03:30.264: E/AndroidRuntime(19098): Caused by: android.database.sqlite.SQLiteException: unable to open database file
01-21 18:03:30.264: E/AndroidRuntime(19098): at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
01-21 18:03:30.264: E/AndroidRuntime(19098): at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1921)
01-21 18:03:30.264: E/AndroidRuntime(19098): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:883)
01-21 18:03:30.264: E/AndroidRuntime(19098): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:168)
01-21 18:03:30.264: E/AndroidRuntime(19098): at com.balance.start.LedgerInfoDB.opentoread(LedgerInfoDB.java:78)
01-21 18:03:30.264: E/AndroidRuntime(19098): at com.balance.start.MainView.onCreate(MainView.java:101)
01-21 18:03:30.264: E/AndroidRuntime(19098): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-21 18:03:30.264: E/AndroidRuntime(19098): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2633)
01-21 18:03:30.264: E/AndroidRuntime(19098): ... 11 more
请给我一些替代方案或告诉我如何避免这种限制。
谢谢。:)