Database 数据库问题:如何诊断和修复问题?

Database 数据库问题:如何诊断和修复问题?,database,android,exception,Database,Android,Exception,我创建了一个将值存储到数据库并检索存储数据的应用程序。在运行模式下运行应用程序时,一切似乎都正常(值被成功存储和检索),但在调试模式下运行时,进程抛出IllegalStateException,到目前为止还没有找到原因 检索对象记录的方法如下所示: public Recording getRecording(String filename) { Recording recording = null; String where = RECORDING_FILENAME + "='

我创建了一个将值存储到数据库并检索存储数据的应用程序。在运行模式下运行应用程序时,一切似乎都正常(值被成功存储和检索),但在调试模式下运行时,进程抛出IllegalStateException,到目前为止还没有找到原因

检索对象记录的方法如下所示:

public Recording getRecording(String filename) {

    Recording recording = null;
    String where = RECORDING_FILENAME + "='" + filename + "'";
    Log.v(TAG, "retrieving recording: filename = " + filename);

    try {
        cursor = db.query(DATABASE_TABLE_RECORDINGS, new String[]{RECORDING_FILENAME, RECORDING_TITLE, RECORDING_TAGS, RECORDING_PRIVACY_LEVEL, RECORDING_LOCATION, RECORDING_GEO_TAGS, RECORDING_GEO_TAGGING_ENABLED, RECORDING_TIME_SECONDS, RECORDING_SELECTED_COMMUNITY}, where, null, null, null, null);

        if (cursor.getCount() > 0) {
            cursor.moveToFirst();
            //String filename = c.getString(0);
            String title = cursor.getString(1);
            String tags = cursor.getString(2);
            int privacyLevel = cursor.getInt(3);
            String location = cursor.getString(4);
            String geoTags = cursor.getString(5);
            int iGeoTaggingEnabled = cursor.getInt(6);
            String recordingTime = cursor.getString(7);
            String communityID = cursor.getString(8);
            cursor.close();
            recording = new Recording(filename, title, tags, privacyLevel, location, geoTags, iGeoTaggingEnabled, recordingTime, communityID);
        }
    }
    catch (SQLException e) {
        String msg = e.getMessage();
        Log.w(TAG, msg);
        recording = null;
    }
    return recording;
}
从另一个类(设置)调用:

在运行上述代码时,一切正常,但我注意到另一个线程中有一个异常:

并且不知道该异常的可能原因是什么,也不知道如何调试该线程中的代码以诊断原因

如果有人知道这里可能存在什么问题,我将非常感激


谢谢大家!

看起来像是
cursor.close()
在一个“
if
”中-这时
SQLiteCursor.finalize()
将抛出一个非法状态异常(我搜索了它)。例如,如果其他进程/线程没有时间提交,您可能会得到一个空记录集

始终关闭它,即使它的结果集为空


为了将来的兼容性,我还建议您按名称而不是索引访问字段。并在
finally{}
块中同时执行
close()
s。

异常的完整堆栈跟踪是什么?或者至少是相关的比特?
private Recording getRecording(String filename) {
    dbAdapter = dbAdapter.open();
    Recording recording = dbAdapter.getRecording(filename);
    dbAdapter.close();
    return recording;
}