我在使用ormlite-android-sqlcipher-4:48库和SQLCipher.for.Android.v3.1.0来执行SQLite文件加密时遇到问题。我相信错误的发生是因为我在使用带有属性'eager = false'的ForeignCollectionField时,如果没有得到错误。我不需要总是false属性来重新加载对象。下面是映射和错误堆栈。
@ForeignCollectionField(eager = false, orderColumnName = CartaoSus.PRINCIPAL, orderAscending = false)
private ForeignCollection cartaoSus;
01-15 13:03:36.055: E/Cursor(3041): Finalizing a Cursor that has not been deactivated or closed. database = /data/data/br.gov.prodemge.sres/databases/sres.db, table = null, query = SELECT * FROM TBCARTAOSUS WHERE ID_USUARIOSUS = ? ORDER BY PRINCIPAL DESC
01-15 13:03:36.055: E/Cursor(3041): net.sqlcipher.database.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
01-15 13:03:36.055: E/Cursor(3041): at net.sqlcipher.database.SQLiteCursor.(SQLiteCursor.java:217)
01-15 13:03:36.055: E/Cursor(3041): at net.sqlcipher.database.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:53)
01-15 13:03:36.055: E/Cursor(3041): at net.sqlcipher.database.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1447)
01-15 13:03:36.055: E/Cursor(3041): at net.sqlcipher.database.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1416)
01-15 13:03:36.055: E/Cursor(3041): at com.j256.ormlite.sqlcipher.android.compat.BasicApiCompatibility.rawQuery(BasicApiCompatibility.java:16)
01-15 13:03:36.055: E/Cursor(3041): at com.j256.ormlite.sqlcipher.android.AndroidCompiledStatement.getCursor(AndroidCompiledStatement.java:180)
01-15 13:03:36.055: E/Cursor(3041): at com.j256.ormlite.sqlcipher.android.AndroidCompiledStatement.runQuery(AndroidCompiledStatement.java:65)
01-15 13:03:36.055: E/Cursor(3041): at com.j256.ormlite.stmt.SelectIterator.(SelectIterator.java:55)
01-15 13:03:36.055: E/Cursor(3041): at com.j256.ormlite.stmt.StatementExecutor.buildIterator(StatementExecutor.java:247)
01-15 13:03:36.055: E/Cursor(3041): at com.j256.ormlite.dao.BaseDaoImpl.createIterator(BaseDaoImpl.java:964)
01-15 13:03:36.055: E/Cursor(3041): at com.j256.ormlite.dao.BaseDaoImpl.iterator(BaseDaoImpl.java:533)
01-15 13:03:36.055: E/Cursor(3041): at com.j256.ormlite.dao.LazyForeignCollection.seperateIteratorThrow(LazyForeignCollection.java:313)
01-15 13:03:36.055: E/Cursor(3041): at com.j256.ormlite.dao.LazyForeignCollection.iteratorThrow(LazyForeignCollection.java:71)
01-15 13:03:36.055: E/Cursor(3041): at com.j256.ormlite.dao.LazyForeignCollection.closeableIterator(LazyForeignCollection.java:60)
01-15 13:03:36.055: E/Cursor(3041): at com.j256.ormlite.dao.LazyForeignCollection.iterator(LazyForeignCollection.java:47)
01-15 13:03:36.055: E/Cursor(3041): at com.j256.ormlite.dao.LazyForeignCollection.iterator(LazyForeignCollection.java:28)
01-15 13:03:36.055: E/Cursor(3041): at br.gov.prodemge.sres.model.UsuarioSUS.getCodigoNumeroCartaoPrincipal(UsuarioSUS.java:791)
01-15 13:03:36.055: E/Cursor(3041): at br.gov.prodemge.sres.components.listview.AdapterListViewResultadoPesquisaCidadaoItem.getView(AdapterListViewResultadoPesquisaCidadaoItem.java:69)
01-15 13:03:36.055: E/Cursor(3041): at android.widget.AbsListView.obtainView(AbsListView.java:2012)
01-15 13:03:36.055: E/Cursor(3041): at android.widget.ListView.makeAndAddView(ListView.java:1772)
01-15 13:03:36.055: E/Cursor(3041): at android.widget.ListView.fillDown(ListView.java:672)
01-15 13:03:36.055: E/Cursor(3041): at android.widget.ListView.fillFromTop(ListView.java:732)
01-15 13:03:36.055: E/Cursor(3041): at android.widget.ListView.layoutChildren(ListView.java:1625)
01-15 13:03:36.055: E/Cursor(3041): at android.widget.AbsListView.onLayout(AbsListView.java:1863)
01-15 13:03:36.055: E/Cursor(3041): at android.view.View.layout(View.java:11278)
01-15 13:03:36.055: E/Cursor(3041): at android.view.ViewGroup.layout(ViewGroup.java:4224)
01-15 13:03:36.055: E/Cursor(3041): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
01-15 13:03:36.055: E/Cursor(3041): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
01-15 13:03:36.055: E/Cursor(3041): at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
01-15 13:03:36.055: E/Cursor(3041): at android.view.View.layout(View.java:11278)
01-15 13:03:36.055: E/Cursor(3041): at android.view.ViewGroup.layout(ViewGroup.java:4224)
01-15 13:03:36.055: E/Cursor(3041): at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
01-15 13:03:36.055: E/Cursor(3041): at android.view.View.layout(View.java:11278)
01-15 13:03:36.055: E/Cursor(3041): at android.view.ViewGroup.layout(ViewGroup.java:4224)
01-15 13:03:36.055: E/Cursor(3041): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
01-15 13:03:36.055: E/Cursor(3041): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
01-15 13:03:36.055: E/Cursor(3041): at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
01-15 13:03:36.055: E/Cursor(3041): at android.view.View.layout(View.java:11278)
01-15 13:03:36.055: E/Cursor(3041): at android.view.ViewGroup.layout(ViewGroup.java:4224)
01-15 13:03:36.055: E/Cursor(3041): at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
01-15 13:03:36.055: E/Cursor(3041): at android.view.View.layout(View.java:11278)
01-15 13:03:36.055: E/Cursor(3041): at android.view.ViewGroup.layout(ViewGroup.java:4224)
01-15 13:03:36.055: E/Cursor(3041): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1489)
01-15 13:03:36.055: E/Cursor(3041): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
01-15 13:03:36.055: E/Cursor(3041): at android.os.Handler.dispatchMessage(Handler.java:99)
01-15 13:03:36.055: E/Cursor(3041): at android.os.Looper.loop(Looper.java:137)
01-15 13:03:36.055: E/Cursor(3041): at android.app.ActivityThread.main(ActivityThread.java:4424)
01-15 13:03:36.055: E/Cursor(3041): at java.lang.reflect.Method.invokeNative(Native Method)
01-15 13:03:36.055: E/Cursor(3041): at java.lang.reflect.Method.invoke(Method.java:511)
01-15 13:03:36.055: E/Cursor(3041): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-15 13:03:36.055: E/Cursor(3041): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-15 13:03:36.055: E/Cursor(3041): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
在ORMLite中使用外部集合时,在某些情况下光标不会自动关闭。形成official ORMLite doc:
警告:只有在使用for()循环一直遍历到迭代器末尾或者直接调用Closeable.close()时,才会关闭基础结果对象。如果您没有在多个线程中遍历此DAO,也可以调用closeLastIterator()。
打破for循环很容易,它会打开游标对象。例如,想象一下通过外部集合循环的以下方法:
public ListItem getSpecificItem(ForeignCollection<ListItem> list) {
for (ListItem item : list) {
if (item.isSpecificOne())
return item;
}
}
这样for循环在到达结束之前就会中断,并且游标对象不会被关闭。您应该在打破循环之前调用ForeignCollection.closeLastIterator()
或重新组织代码以使循环一直持续到最后。