所有
i am working on one application in which i have to used database.
在那里我使用静态游标并返回cursor.in onDestroye()我关闭光标但我的问题是我使用游标作为静态所以问题是当我运行应用程序并使用游标第一次不显示错误,但第二次访问游标时显示错误:
Finalizing a Cursor that has not been deactivated or closed. database = /data/data/com.technosoft.listia/databases/Listia, table = null, query = select * from Browser where id=2
07-20 12:37:02.292: ERROR/Cursor(588): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
07-20 12:37:02.292: ERROR/Cursor(588): at android.database.sqlite.SQLiteCursor.<init>(SQLiteCursor.java:210)
07-20 12:37:02.292: ERROR/Cursor(588): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:53)
07-20 12:37:02.292: ERROR/Cursor(588): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
07-20 12:37:02.292: ERROR/Cursor(588): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1315)
07-20 12:37:02.292: ERROR/Cursor(588): at com.technosoft.listia.DataBaseListia.SelectBrosertab(DataBaseListia.java:103)
07-20 12:37:02.292: ERROR/Cursor(588): at com.technosoft.browserTab.BrowserCategoryList.ListviewDisplayMrthod(BrowserCategoryList.java:356)
07-20 12:37:02.292: ERROR/Cursor(588): at com.technosoft.browserTab.BrowserCategoryList$1.handleMessage(BrowserCategoryList.java:347)
07-20 12:37:02.292: ERROR/Cursor(588): at android.os.Handler.dispatchMessage(Handler.java:99)
07-20 12:37:02.292: ERROR/Cursor(588): at android.os.Looper.loop(Looper.java:123)
07-20 12:37:02.292: ERROR/Cursor(588): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-20 12:37:02.292: ERROR/Cursor(588): at java.lang.reflect.Method.invokeNative(Native Method)
07-20 12:37:02.292: ERROR/Cursor(588): at java.lang.reflect.Method.invoke(Method.java:521)
07-20 12:37:02.292: ERROR/Cursor(588): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-20 12:37:02.292: ERROR/Cursor(588): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-20 12:37:02.292: ERROR/Cursor(588): at dalvik.system.NativeStart.main(Native Method)
我怎样摆脱这个...... 请尽早帮助我
谢谢......
答案 0 :(得分:1)
当你启动应用程序时,它以oncreate方法开始,当你将游标声明为静态时,所以当你回来时,调用onDestroy方法并关闭游标。
现在第二次以onResume方法开始,所以当时光标已经关闭,所以在查询时它不会打开你需要再次打开那个光标。
在初始化游标之后保持游标调用此startManagingCursor(Cursor对象),这样它将由应用程序管理,您不需要显式关闭游标