【问题标题】:Android: Error , Ljava/lang/IllegalStateException;: Finalizing cursor , t_forms that has not been deactivated or closedAndroid: Error , Ljava/lang/IllegalStateException;: Finalizing cursor , t_forms 尚未停用或关闭
【发布时间】:2011-08-09 20:15:30
【问题描述】:

我有一个 DB 助手类,它可以帮助我在 Android 1.6 中插入和删除信息片段的记录。

当我删除一条记录并在之后插入一条新记录时,我收到以下错误

Ljava/lang/IllegalStateException;:在尚未停用或关闭的 t_forms 上完成游标 android.database.sqlite.SQLiteCursor@43d63338

我在网上搜索了答案,大多数论坛帖子都说游标没有关闭。实际上我正在执行的操作并没有真正返回记录集数据,所以我有点困惑为什么 logcat会抛出这个错误...

所以这两个函数一个接一个地被调用..

//---deletes a particular form---
public boolean deleteForm(int formID) 
{
   return db.delete(DATABASE_TABLE, KEY_FORM_ID + "=" + formID, null) > 0;
}

//---insert a form into the database---
public long insertForm(int form_id, String lform_name, String lform_description, String sdcardPath) 
{
    ContentValues initialValues = new ContentValues();
    initialValues.put(KEY_FORM_ID, form_id);
    initialValues.put(KEY_FORM_NAME, lform_name);
    initialValues.put(KEY_FORM_DESC, lform_description);
    initialValues.put(KEY_SDCARDPATH, sdcardPath);
    return db.insert(DATABASE_TABLE, null, initialValues);
}

可能是什么问题?

【问题讨论】:

  • 您提供的代码不足以说明错误的确切来源。

标签: android sqlite


【解决方案1】:

您提供的代码还不够。但首先像这样关闭 onDestroy 和 onStop 中的光标:

if(mCursor!= null && !mCursor.isClosed())
   mCursor.close();

然后尝试在使用光标对象的位置之后调用startManagingCursor(cursor),如果您使用它进行查询等,请在使用光标进行的操作之后调用它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-26
    • 1970-01-01
    • 2012-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多