Я надеюсь, что кто-то может помочь мне с этим. Я не могу воспроизвести эту ошибку, но получаю огромное количество сообщений о сбоях. Ниже приведена трассировка стека и соответствующий код. Я думал, добавив "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)));
}