Android的SQLite的例外:无法关闭,由于取消定型化报表 [英] Android SQLite Exception: unable to close due to unfinalised statements

查看:210
本文介绍了Android的SQLite的例外:无法关闭,由于取消定型化报表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个Android的购物管理应用程序,并试图靠近我的SQLite数据库表之一时所遇到的一个错误。

I am writing an android shopping manager application and have come across an error when trying to close one of my SQLite database tables.

ItemsDb idb = new ItemsDb(this);

idb.open();

ArrayList<String> itemNames = idb.getItemNames();

for(int i=0; i < itemNames.size(); i++){

    String itemName = itemNames.get(i);

    String itemID = idb.getItemID(itemName);
    String itemName = idb.getItemNames().get(i);
    String itemPrices = idb.getItemPrices().get(i);
    String itemQuantity = idb.getItemQuantities().get(i);               
    String dateBought = idb.getDateBought(itemName);    
    String decayRate = idb.getDecayRate(itemName);
    String decayType = idb.getDecayType(itemName);
    String lastDecay = idb.getLastDecay(itemName);
    String prevQuantity = idb.getPreviousQuantity(itemName);
}

idb.close();

这不与其他调用发生在这个类,所以,我想知道是否是因为有很多电话来这里数据库的循环。 错误是 SQLite的例外:无法关闭,由于取消定型化语句

This doesn't happen with other calls to this class so and I am wondering if it is because there is a loop with a lot of calls to the database here. The error is SQLite Exception: unable to close due to unfinalised statements.

从ItemsDb类中的错误行是在这里

The error line from the "ItemsDb" class is here

    public ItemsDb(Context c){

        ourContext = c;
    }

    public ItemsDb open() throws SQLException{
        ourHelper = new DbHelper(ourContext);
        ourDatabase = ourHelper.getWritableDatabase();
        return this;
    }

    public void close(){
        ourHelper.close();
    }

显然sqlite3的有finalize方法销毁previous DB电话,但我不知道如何实现这一或者即使有必要在这里。

Apparently SQLite3 has a finalize method for destroying previous DB calls but I am not sure how to implement this or even if it is necessary here.

任何帮助将是巨大的。

推荐答案

看来问题光标有关,感谢Jivings。我没有关闭游标后,我查询的数据库,这意味着一定的参考数据库是无效的。

It seems the problem was cursor related, thanks Jivings. I wasn't closing the cursor after I queried the database, which meant certain references to the database were invalid.

public String getName(String id) throws SQLException{
    String[] columns = new String[]{ KEY_ItemID, KEY_NAME};
    Cursor c = ourDatabase.query(DATABASE_TABLE, columns, KEY_ItemID + "='" + id + "'", null, null, null, null);
    if(c != null){
        c.moveToFirst();
        String name = c.getString(1);
        c.close();
        return name;
    }
    return null;
}

调用c.close似乎做的伎俩。

Calling "c.close" seemed to do the trick.

这篇关于Android的SQLite的例外:无法关闭,由于取消定型化报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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