Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android中的游标和SQLite错误_Android_Database_Sqlite_Cursor - Fatal编程技术网

android中的游标和SQLite错误

android中的游标和SQLite错误,android,database,sqlite,cursor,Android,Database,Sqlite,Cursor,读取数据库时,光标出现错误: 04-07 18:11:25.672: ERROR/AndroidRuntime(5801): android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. # Open Cursors=666 (# cursors opened by this proc=666) 这是在网上发生的 cursor.getCount() 整个文件是8kb,

读取数据库时,光标出现错误:

04-07 18:11:25.672: ERROR/AndroidRuntime(5801): android.database.CursorWindowAllocationException: Cursor window allocation of 2048 kb failed. # Open Cursors=666 (# cursors opened by this proc=666)
这是在网上发生的

cursor.getCount()
整个文件是8kb,它有32行,但是ID从737到768,这是问题所在吗

(我注意到,如果ID低于600,则没有问题)

(OP在问题编辑中回答的问题。转换为社区wiki答案。请参阅)

OP写道:

我解决了这个问题。我的代码是:

我改为:


我认为在onDestroy()上关闭了光标。

您真的应该在
finally
块中关闭光标,以确保即使发生异常也关闭光标

public News getNewsWithID(int-id){
游标c=bdd.query(表_NEWS,新字符串[]{COL_ID,COL_ASSO,COL_DATE,COL_HEURE,COL_TYPE,COL_TITRE,COL_CONTENU,COL_SERVEURID},COL_ID+“=”+ID+”,null,null,null,null);
试一试{
返回cursorToNews(c);
}最后{
c、 close();
}
}

更多的代码会有帮助。。。错误消息似乎表明您正在同时打开许多游标。
public News getNewsWithID(int id){
        Cursor c = bdd.query(TABLE_NEWS, new String[] {COL_ID, COL_ASSO, COL_DATE, COL_HEURE, COL_TYPE, COL_TITRE, COL_CONTENU, COL_SERVEURID}, COL_ID +"='"+ id +"'" , null, null, null, null);
        return cursorToNews(c);
    }
public News getNewsWithID(int id){
        Cursor c = bdd.query(TABLE_NEWS, new String[] {COL_ID, COL_ASSO, COL_DATE, COL_HEURE, COL_TYPE, COL_TITRE, COL_CONTENU, COL_SERVEURID}, COL_ID +"='"+ id +"'" , null, null, null, null);
        News temp = cursorToNews(c);
        c.close();
        return temp;
    }