我的应用程序到目前为止工作正常,但在某些设备上出现错误(例如Android 4.1或4.3)
@echo off
setlocal EnableDelayedExpansion
rem Define the text for the options
set "num=0"
for %%a in ("First option"
"Second option"
"Third option"
"Fourth option") do (
set /A num+=1
set "msg[!num!]=%%~a"
set "opt[!num!]= "
)
set "digits=0123456789"
:select
(cls
echo Press digit to mark/unmark options, or X to end
echo/
for /L %%i in (1,1,%num%) do echo !digits:~%%i,1!. [!opt[%%i]!] !msg[%%i]!
)
choice /C !digits:~1,%num%!X /N > NUL
if %errorlevel% gtr %num% goto endSelect
set "sel=%errorlevel%"
if "!opt[%sel%]!" equ "X" (set "opt[%sel%]= ") else set "opt[%sel%]=X"
goto select
:endSelect
echo/
echo/
for /L %%i in (1,1,%num%) do (
if "!opt[%%i]!" equ "X" (
echo %%i selected
)
)
在DBManager课程中我有这个:
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
Caused by: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:209)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:235)
at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:188)
在DBHelper中:
public class DBManager {
public DBHelper helper;
private SQLiteDatabase db;
private Cursor c;
public DBManager(Context context) {
helper = new DBHelper(context);
db = helper.getReadableDatabase();
// db = helper.getWritableDatabase();
}
清单等没问题,但我不明白为什么在某些设备上会出现SQLiteCantOpenDatabaseException。我希望有人可以帮我解决这个问题? Thanx提前
答案 0 :(得分:0)
您正在将DATABASE_NAME
设置为以Environment.getExternalStorageDirectory()返回的目录为根的路径。
引用getExternalStorageDirectory()
的文档:
如果已挂载此目录,则该目录当前可能无法访问 由用户在他们的计算机上,已从设备中删除,或 还发生了其他一些问题。
如果您不需要指定数据库文件的位置,则应该只指定文件名(例如“MyDB”),Android框架将为您确定合适的路径。
[增订]
通常,DB(可能包含非常重要的数据,甚至可能包含敏感的用户信息)不会存储在外部存储中,因为:
如果要创建数据库的备份副本(并将其放在外部存储中),请参阅this answer。