活动无法正常管理光标。 [英] Activity not properly managing cursor.

查看:90
本文介绍了活动无法正常管理光标。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有填充列表,并从游标做一些其他的事情的活动。我从回到它基于标准的Andr​​oid SQLite的查询到我的数据库的方法得到光标。该方法在我的提供SQLHelper 类中定义。该方法将打开的数据库,查询,关闭数据库,并返回光标。光标已经在活动中被收集后,我称之为 startManagingCursor(光标);

I have an activity that populates a list and does some other things from a cursor. I get the cursor from a method that returns it based on a standard android SQLite query to my database. The method is defined in my SQLHelper class. The method opens the database, queries, closed the database, and returns the cursor. After the cursor has been collected in the activity, I call startManagingCursor(cursor);

所有这一切工作正常。

当我启动子的活性,然后再回到第一个问题发生。我得到一个强制关闭与下面的输出:

The problem happens when I launch a sub activity and then come back to the first one. I get a force close with the following output:

07-28 18:11:04.674: ERROR/AndroidRuntime(224): java.lang.RuntimeException: Unable to resume activity {blabla}: java.lang.IllegalStateException: mQuery SELECT * FROM vehicles WHERE _id=? 1 
...
07-28 18:11:04.674: ERROR/AndroidRuntime(224): Caused by: java.lang.IllegalStateException: mQuery SELECT * FROM vehicles WHERE _id=? 1 
07-28 18:11:04.674: ERROR/AndroidRuntime(224):     at android.database.sqlite.SQLiteQuery.requery(SQLiteQuery.java:162)
07-28 18:11:04.674: ERROR/AndroidRuntime(224):     at android.database.sqlite.SQLiteCursor.requery(SQLiteCursor.java:536)

...
07-28 18:11:04.674: ERROR/AndroidRuntime(224): Caused by: android.database.sqlite.SQLiteMisuseException: library routine called out of sequence: handle 0x0
07-28 18:11:04.674: ERROR/AndroidRuntime(224):     at android.database.sqlite.SQLiteProgram.native_bind_string(Native Method)
07-28 18:11:04.674: ERROR/AndroidRuntime(224):     at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:178)
07-28 18:11:04.674: ERROR/AndroidRuntime(224):     at android.database.sqlite.SQLiteQuery.requery(SQLiteQuery.java:153)

的问题是很明显当它试图重新查询光标。如果我手动关闭游标之前,我启动的意图,那么它工作正常。但后来我需要手动重新查询它是不是 startManagingCursor整个点()?我在,它们都以同样的方式创建活动两个光标,我呼吁开始管理两个光标,既造成简历崩溃。

The problem is apparently when it is trying to re-query the cursor. If I close the cursor manually before I launch the intent, then it works fine. But then I need to re-query it manually and isn't that the entire point of startManagingCursor()? I have two cursors in the activity that are both created in the same way and I call start managing cursor on both, both cause a crash on resume.

有没有别的东西,我需要做的就是我的活动,以妥善管理我的游标?
谢谢你。

Is there something else I need to do to get my activity to properly manage my cursors? Thanks.

推荐答案

好了,事实证明,Cursor.requery()是德preciated每次我试图把它的时间我得到了同样的错误。 startManagingCursor()调用被重新查询,因为我想它应该,而这又引起了我的问题有...我不知道为什么重新查询在这种情况下导致错误,我已经成功地使用过。

Well, it turns out that Cursor.requery() is depreciated and I was getting the same error every time I tried to call it. startManagingCursor() was calling requery, as I suppose it should, and that in turn was causing my problems there... I'm not sure why requery is causing an error in this instance, I've used it successfully before.

我结束了重新安排一些code,并把我的光标= SQLHelper.getwhatevercursor()code到onResume()代替的onCreate,因为onResume是的onCreate后立即叫反正。所推荐的尼古拉我也逼近的onPause光标()。

I ended up rearranging some code, and putting my cursor = SQLHelper.getwhatevercursor() code into onResume() instead of onCreate, as onResume is called right after onCreate anyway. As recommended by Nikola I am also closing the cursors in onPause().

这似乎是现在的工作...

This seems to be working now...

这篇关于活动无法正常管理光标。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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