gpt4 book ai didi

Android 6.0 更新导致 DB sqlite 在 init 期间崩溃

转载 作者:太空宇宙 更新时间:2023-11-03 11:06:09 24 4
gpt4 key购买 nike

我在应用程序类文件中创建数据库的代码可在数千台设备上运行,但最近我多次遇到崩溃,全部来自 android 6.0,因此它可能与新的 android 版本有关。此外,此崩溃仅在以下给定的 3 台设备上出现。请告知如何解决此问题..

设备:Canvas A1 (AQ4501_sprout)、Dream Uno (Mi-498_sprout)、Sparkle V (Sparkle_V_sprout)

崩溃日志:

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:207)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:191)
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:806)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:791)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:571)
at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:269)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:223)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)

引用代码(崩溃发生在db.getWritableDatabase()):

//Application class
public class MyApp extends Application {

@Override
public void onCreate() {
super.onCreate();
dataBaseInit();
}

private void dataBaseInit() {
db = new MyDatabase(getApplicationContext());

// This will open an reference to database
dataBaseRef = db.getWritableDatabase();
}
}

//Database class
public class MyDatabase extends SQLiteOpenHelper {

// All Static variables
// Database Version
private static final int DATABASE_VERSION = 1;

// Database Name
private static final String DATABASE_NAME = "myDatabase";

public MyDatabase(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

在 db.getWritableDatabase() 发生崩溃。

请告知如何解决此问题。

最佳答案

我在 list 中添加“android.permission.WRITE_EXTERNAL_STORAGE”权限后仍然遇到问题,但仍然像上面一样崩溃。

关于Android 6.0 更新导致 DB sqlite 在 init 期间崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33357765/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com