Java代码
SQLiteDatabase sqLiteDatabase=SQLiteDatabase.openDatabase("file:///android_asset/dbCityCategory.db",null,SQLiteDatabase.OPEN_READONLY);
Cursor cursor=sqLiteDatabase.query("city",null,null,null,null,null,null);
cursor.moveToFirst();
do {
arrayList.add(cursor.getString(1));
}while (cursor.moveToNext());
cursor.close();
sqLiteDatabase.close();
Exeption
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.SQLiteDatabase.openDatabase(SQLiteDatabase.java:669)
at com.eranewgames.autolike.Services.onCreate(Services.java:80)
如何查看Android Studio数据库? 如何查看Android Studio数据库?
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode==1){
if(grantResults[0]== PackageManager.PERMISSION_GRANTED){
SQLiteDatabase sqLiteDatabase= SQLiteDatabase.openDatabase(MyCustomLib.ASSETS+"dbCityCategory.db",null,SQLiteDatabase.OPEN_READWRITE);
sqLiteDatabase.close();
}
}
}
我添加了权限,但错误仍然是