当前位置 : 主页 > 手机开发 > android >

由于Android的未定型语句而无法关闭

来源:互联网 收集:自由互联 发布时间:2021-06-11
我希望有人可以帮助我解决这个问题.我无法重现此错误,但收到了大量的崩溃报告.下面是堆栈跟踪和相关代码.我想添加“cursor.close();”会解决问题,但事实并非如此.任何人都可以弄清楚
我希望有人可以帮助我解决这个问题.我无法重现此错误,但收到了大量的崩溃报告.下面是堆栈跟踪和相关代码.我想添加“cursor.close();”会解决问题,但事实并非如此.任何人都可以弄清楚发生了什么事吗?第187行是mDbAdapter.close();

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.companionfree.WLThemeViewer/com.companionfree.WLThemeViewer.Viewer}: android.database.sqlite.SQLiteException: unable to close due to unfinalised statements
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2753)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769)
at android.app.ActivityThread.access$2500(ActivityThread.java:129)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2117)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4717)
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:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: unable to close due to unfinalised statements
at android.database.sqlite.SQLiteDatabase.dbclose(Native Method)
at android.database.sqlite.SQLiteDatabase.onAllReferencesReleased(SQLiteDatabase.java:323)
at android.database.sqlite.SQLiteDatabase.close(SQLiteDatabase.java:886)
at android.database.sqlite.SQLiteOpenHelper.close(SQLiteOpenHelper.java:191)
at com.companionfree.WLThemeViewer.DbAdapter.close(DbAdapter.java:163)
at com.companionfree.WLThemeViewer.Viewer.getNavData(Viewer.java:178)
at com.companionfree.WLThemeViewer.Viewer.onCreate(Viewer.java:65)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2717)
... 11 more

资源:

private void getNavData() {
    mDbAdapter.open();
    //      mNav = MainActivity.mDbAdapter.getNav(mMode);
    //      startManagingCursor(mNav);
    Cursor cursor = mDbAdapter.getNav(mMode);

    int i=0;
    if (!(mMode==MainActivity.MODE_FAVORITE_CREATORS)) {
        mNav2 = new int[cursor.getCount()];
        while (cursor.moveToNext()) {

            String name = cursor.getString(cursor.getColumnIndexOrThrow(DbAdapter.KEY_NAME));
            mNav2[i] = mDbAdapter.getPrimaryRowId(name);

            i++;
        }
    } else {        
        int[] temp = new int[9999];
        while (cursor.moveToNext()) {
            String creatorName = cursor.getString(cursor.getColumnIndexOrThrow(DbAdapter.KEY_NAME));
            Cursor creatorThemes = mDbAdapter.getCreatorThemes(creatorName);
            while (creatorThemes.moveToNext()) {
                String name = creatorThemes.getString(creatorThemes.getColumnIndexOrThrow(DbAdapter.KEY_NAME));
                temp[i] = mDbAdapter.getPrimaryRowId(name);
                i++;

            }
 creatorThemes.close();
        }
        mNav2 = new int[i];
        for (int c=0;c<mNav2.length;c++) {
            mNav2[c] = temp[c];
        }
    }
    cursor.close();
    mDbAdapter.close();
}

DbAdapter.java

public void close() {
    mDbHelper.close();
}

编辑:我尝试了第一个解决方案并在市场上更新了它.这是最新的崩溃报告:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.companionfree.WLThemeViewer/com.companionfree.WLThemeViewer.Viewer}: android.database.sqlite.SQLiteException: unable to close due to unfinalised statements
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2685)
at android.app.ActivityThread.access$2300(ActivityThread.java:126)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2038)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4633)
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 close due to unfinalised statements
at android.database.sqlite.SQLiteDatabase.dbclose(Native Method)
at android.database.sqlite.SQLiteDatabase.onAllReferencesReleased(SQLiteDatabase.java:322)
at android.database.sqlite.SQLiteDatabase.close(SQLiteDatabase.java:990)
at android.database.sqlite.SQLiteOpenHelper.close(SQLiteOpenHelper.java:191)
at com.companionfree.WLThemeViewer.DbAdapter.close(DbAdapter.java:163)
at com.companionfree.WLThemeViewer.Viewer.getNavData(Viewer.java:179)
at com.companionfree.WLThemeViewer.Viewer.onCreate(Viewer.java:65)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2633)
... 11 more

As requested in the comments

    public int getPrimaryRowId(String name) {
        Cursor cursor =  mDb.query(TABLE_THEMES_V2, new String[] {KEY_ROWID,KEY_NAME}, 
                KEY_NAME + " = '" + name +"'", null, null, null, null);
        cursor.moveToFirst();
        return Integer.parseInt(cursor.getString(cursor.getColumnIndexOrThrow(KEY_ROWID)));
    }
你在一个循环中创建新游标(creatorThemes)并且从不清理它们中的任何一个
网友评论