1

我目前正在编写一个必须使用 SQLite 数据库的 Android 应用程序。在某些时候,数据库(其中存储有数据)无法再打开,应用程序崩溃,我无法再次打开它。当我重新安装该应用程序时,它再次正常工作。我正在使用 SqliteOpenHelper。

日志猫:

    Failed to open database '/data/data/jonas.examinationscheduler.com.examinationscheduler/KlasseLocal'.
    android.database.sqlite.SQLiteException: not an error (code 0)
    at android.database.sqlite.SQLiteConnection.nativeRegisterLocalizedCollators(Native Method)
    at android.database.sqlite.SQLiteConnection.setLocaleFromConfiguration(SQLiteConnection.java:359)
    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:216)
    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)
    at jonas.examinationscheduler.com.examinationscheduler.SchulenBaseHandler.getAllKlassen(SchulenBaseHandler.java:74)
    at jonas.examinationscheduler.com.examinationscheduler.PlaeneFragment.getAllePlaene(PlaeneFragment.java:87)
    at jonas.examinationscheduler.com.examinationscheduler.PlaeneFragment.onCreateView(PlaeneFragment.java:41)
    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1252)
    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:742)
    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
    at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
    at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
    at android.support.v4.view.ViewPager.populate(ViewPager.java:1177)
    at android.support.v4.view.ViewPager.populate(ViewPager.java:1025)
    at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1545)
    at android.view.View.measure(View.java:18788)
    at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
    at android.view.View.measure(View.java:18788)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
    at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:668)
    at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:735)
    at android.view.View.measure(View.java:18788)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
    at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
    at android.view.View.measure(View.java:18788)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
    at android.view.View.measure(View.java:18788)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
    at android.view.View.measure(View.java:18788)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)

抛出错误的地方(在我的 SqliteOpenHelper 类中):

public List<KlasseLocal> getAllKlassen(){
    List<KlasseLocal> klassenListe = new ArrayList<KlasseLocal>();
    // Select All Query
    String selectQuery = "SELECT  * FROM " + TABLE_KLASSEN;

    SQLiteDatabase db = getWritableDatabase(); //The error gets Thrown here
    Cursor cursor = db.rawQuery(selectQuery, null);

    // looping through all rows and adding to list
    if (cursor.moveToFirst()) {
        do {
            KlasseLocal klasse = new KlasseLocal();
            klasse.setNummer(Integer.parseInt(cursor.getString(0)));
            klasse.setSchule(cursor.getString(1));
            klasse.setKlasse(cursor.getString(2));
            // Adding klasse to list
            klassenListe.add(klasse);
        } while (cursor.moveToNext());
    }
    cursor.close();
    // return contact list
    return klassenListe;
}

我如何调用该方法:

List<KlasseLocal> list = new SchulenBaseHandler(getContext()).getAllKlassen();
4

0 回答 0