Android:完成尚未停用或关闭的游标
我有一个需要使用 SQLite(Android 的数据库)的应用程序。
我已经为我的模型和数据帮助程序创建了一个类似 JPA 的结构。 问题是当我在 helper.search(int id) 上调用另一个 aHelper.search(int id) 时,会记录“最终确定游标”错误。
return Child(cursor.getInt(0), new ParentHelper.search(cursor.getInt(1)));
我的类似 JPA 的模型和 datahelper 的结构如下所示。
class Parent {
int id;
String name
// constructor with field-parameter
// getters and setters
}
class Child {
int id;
Parent parent;
// constructor with field-parameter
// getters and setters
}
class ParentHelper {
// necessary SQLiteImpelemntations
Parent search(int id) {
// new Cursor implementation
cursor.moveToFirst();
return new Parent(cursor.getInt(0), cursor.getString(1));
}
}
class ChildHelper {
ParentHelper parentHelper;
void close() {
parenHelper.close()
SQLiteDatabase.close();
SQLiteOpenHelper.close();
}
ArrayList searchAll() {
// new Cursor implementation
cursor.moveToFirst();
Child child = new Child(cursor.getInt(0), parentHelper.search(cursor.getInt(1)))
ArrayList.add(child)
cursor.close();
}
// necessary SQLiteImpelemntations
Child search(int id) {
// new Cursor implemenation
cursor.moveToFirst();
Child child = new Child(cursor.getInt(0), parentHelper.search(cursor.getInt(1)))
cursor.close();
return child;
}
}
I have an application which requires the use of SQLite (Android's database).
I have created a JPA-like structure to my model and datahelper.
The problem is when I call another aHelper.search(int id) while on a helper.search(int id), the Finalizing a Cursor error logs.
return Child(cursor.getInt(0), new ParentHelper.search(cursor.getInt(1)));
The structure to my JPA-like model and datahelper goes like this.
class Parent {
int id;
String name
// constructor with field-parameter
// getters and setters
}
class Child {
int id;
Parent parent;
// constructor with field-parameter
// getters and setters
}
class ParentHelper {
// necessary SQLiteImpelemntations
Parent search(int id) {
// new Cursor implementation
cursor.moveToFirst();
return new Parent(cursor.getInt(0), cursor.getString(1));
}
}
class ChildHelper {
ParentHelper parentHelper;
void close() {
parenHelper.close()
SQLiteDatabase.close();
SQLiteOpenHelper.close();
}
ArrayList searchAll() {
// new Cursor implementation
cursor.moveToFirst();
Child child = new Child(cursor.getInt(0), parentHelper.search(cursor.getInt(1)))
ArrayList.add(child)
cursor.close();
}
// necessary SQLiteImpelemntations
Child search(int id) {
// new Cursor implemenation
cursor.moveToFirst();
Child child = new Child(cursor.getInt(0), parentHelper.search(cursor.getInt(1)))
cursor.close();
return child;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在返回值之前尝试关闭游标。
对您的 ChildHelper 执行相同的操作。
Try closing your Cursor before returning the value.
Do the same for your ChildHelper.