关闭从未明确地称为 [英] Close was never explicitly called

查看:160
本文介绍了关闭从未明确地称为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个是由一个SQLite数据库源列表视图。我叫fillData()在几个不同点更新列表视图。

I have a listview that is sourced by an sqlite db. I call fillData() at several different points to update the listview.

private void fillData() {
        mDbHelper.open();
        Cursor c = mDbHelper.fetchAllNotes(table, columns, selection, selectionArgs, null, null);
        startManagingCursor(c);

        String[] from = new String[] { "quantity", "color", "style" };
        int[] to = new int[] { R.id.textQuantity, R.id.textColor, R.id.textStyle };
        setListAdapter(new SimpleCursorAdapter(this, R.layout.recordrow, c, from, to) {
            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                View v = super.getView(position, convertView, parent);
                return v;
            }
        });
}

这是工作......问题是,当我打开各地的活动/关闭/跳,我得到了logcat中的错误。这不,虽然程序崩溃。该错误是:

请确保你明确地调用close()在你的光标

close()方法从未明确要求对数据库

That works... problem is, when I open/close/jump around activities, I get errors in logcat. It doesn't crash the program though. The errors are:

Please ensure you explicitly call close() on your cursor
and
close() was never explicitly called on database

所以,下});如果我把mDbHelper.close()崩溃说数据库无法打开。如果我把c.close(),我的ListView从来没有填充。我试图把它们放在其他地方,这让我的错误说法光标/数据库已经关闭。什么任何想法办?

So under }); if I put mDbHelper.close() it crashes saying database not open. If I put c.close(), my listview never populates. I've tried putting them in various other places and it gives me errors saying cursor/database already closed. Any ideas on what to do?

推荐答案

如果一切都在一个活动刚刚打开的数据库和光标的onCreate()和关闭的onDestroy()。 另一种选择是使用单或smoething将操作之前,打开数据库或光标,如果它是空。

If everything is in one Activity just open database and cursor in onCreate() and close in onDestroy(). Another option is to use singleton or smoething which will open database or cursor before operations if it's null.

的误差修改是造成的,因为如果你在完成数据库操作,你应该关闭它。

The erros are caused because if you are finishing operations on database you should close it.

这篇关于关闭从未明确地称为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆