Why some users are getting SQLiteException at SQLiteDatabase.dbopen()?

半腔热情 提交于 2020-01-13 19:30:11

问题


Here is the exception:

java.lang.RuntimeException: Unable to start activity ComponentInfo{spb.bridges/spb.bridges.Bridges}: android.database.sqlite.SQLiteException: unable to open database file
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: unable to open database file
at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1921)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:883)
at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:960)
at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:953)
at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:602)
at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:98)
at spb.bridges.DbAdapter.open(DbAdapter.java:172)
at spb.bridges.Bridges.onCreate(Bridges.java:90)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)

and here is the code of DbAdapter.open:

public DbAdapter open() throws SQLException {
    mDbHelper = new DatabaseHelper(mCtx);
    mDb = mDbHelper.getWritableDatabase();
    return this;
}

Bridges.onCreate:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.bridges_list);
    mDbHelper = new DbAdapter(this);
    mDbHelper.open();

回答1:


It looks like you context is not fully initialized when you open your database.

In your Bridges.onCreate method, do you call super.onCreate? setContentView before any other operations?



来源:https://stackoverflow.com/questions/6556060/why-some-users-are-getting-sqliteexception-at-sqlitedatabase-dbopen

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!