【问题标题】:Ormlite SQLiteCursor: close cursor on null twice or moreOrmlite SQLiteCursor:在 null 上关闭游标两次或更多次
【发布时间】:2014-08-11 14:06:35
【问题描述】:

我有 Coach 类,其中包含 ScheduleEntity 对象的集合;

public class Coach{

    @ForeignCollectionField(columnName = FIELD_SCHEDULE_ENTITY)
    private Collection<ScheduleEntity> scheduleEntities;
}

[...]

public class ScheduleEntity {

    @DatabaseField(columnName = FIELD_COACH, foreign = true)
    private Coach coach;
}

我想先检索ScheduleEntity 作为教练。

当我使用QueryBuilder:

public ScheduleEntity getFirstScheduleForCoach(Coach coach) throws SQLException {
    QueryBuilder<ScheduleEntity, Long> queryBuilder = scheduleEntityDao.queryBuilder();
    queryBuilder
            .where()
            .eq(ScheduleEntity.FIELD_COACH, coach);
   return scheduleEntityDao.queryForFirst(queryBuilder.prepare());

logcat 中出现了一些奇怪的信息:

Close cursor android.database.sqlite.SQLiteCursor@42321aa0 on null twice or more

但是当我以另一种方式这样做时:

return scheduleEntityDao.queryForEq(ScheduleEntity.FIELD_COACH, coach).iterator().next();

一切都很好(不要关心可能的空指针)。

这些信息是什么意思?我做错了什么还是只是正常行为?

【问题讨论】:

  • 对不起,我没用过ORMLite。
  • 你有没有找到原因,或者至少如何关闭它?
  • @NadavFima 不,这只是警告,其他一切正常。我无视它
  • 是的,它工作正常。在 Play 商店中的应用程序的 logcat 中有这个真是太可惜了。
  • @Than 查看我发布的答案。 :) 现在查看 logcat 变得容易多了。

标签: android android-sqlite ormlite


【解决方案1】:

我继续下载了 ORMLite 的代码。

在第 89 行的 AndroidCompiledStatement 类中,我将 close 方法更改如下:

之前

public void close() throws IOException {
    if (cursor != null) {
        try {
            cursor.close();
        } catch (android.database.SQLException e) {
            throw new IOException("Problems closing Android cursor", e);
        }
    }
    cancellationHook = null;
}

之后

public void close() throws IOException {
    if (cursor != null && !cursor.isClosed()) {
        try {
            cursor.close();
        } catch (android.database.SQLException e) {
            throw new IOException("Problems closing Android cursor", e);
        }
    }
    cancellationHook = null;
}

只需检查光标是否已经关闭,这对我来说几乎是固定的,尽管您必须将 ormlite-android git 克隆到您的项目中。

【讨论】:

  • 看起来很有希望,我会试试的
  • 为了记录,这在ormlite 5.0版本中已修复。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-18
  • 2021-04-10
  • 2012-02-21
  • 2021-12-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多