由于未完成的声明Android无法关闭 [英] Unable to close due to unfinalised statements Android

查看:86
本文介绍了由于未完成的声明Android无法关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人可以帮助我解决这个问题。我无法重现此错误,但正在从中收到大量崩溃报告。以下是堆栈跟踪和相关代码。我想添加 cursor.close();可以解决问题,但没有解决。谁能知道发生了什么事?第187行是mDbAdapter.close();

I hope someone can help me out with this. I can't reproduce this error but am receiving a huge amount of crash reports from it. Below is the stack trace and relevant code. I thought adding "cursor.close();" would solve the problem but it did not. Can anyone figure out what is going on? Line 187 is 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

DbAdapter.java

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

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

I tried the first solution and updated it in the market. Here is the most recent crash report:

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 ),并且永远不要清理其中的任何一个

You're creating new cursors in a loop (creatorThemes) and never cleaning any of them up

这篇关于由于未完成的声明Android无法关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆