Finalizing a Cursor that has not been deactivated or closed non-fatal error

前端 未结 9 1485
慢半拍i
慢半拍i 2020-12-07 19:27

i\'m getting a \"Finalizing a Cursor that has not been deactivated or closed\" error on this piece of code. The code is used to fill a listview.

Since it\'s a non

9条回答
  •  猫巷女王i
    2020-12-07 19:29

    Scott,

    I ran into the same problem as you. Before you close your database, i.e. "db.close()," make sure that your cursors are closed first, i.e. "mCursor.close()"

    Like so:

    private void updateList()
    { 
        DBAdapter db = new DBAdapter(this);
        db.open();
    
        //load all waiting alarm
        mCursor=db.getTitles("state<2"); 
        setListAdapter(new MyCursorAdapter(this, mCursor)); 
        registerForContextMenu(getListView()); 
    
        // Let's close the cursor.
        mCursor.close();
        db.close(); 
    } 
    

    You mentioned that if you closed your cursor your list view stays empty. I recommend you pass the information over to a class and copy it over (allocate the memory) then close the cursor.

提交回复
热议问题