最终确定游标没有停用

时间:2012-07-01 21:45:52

标签: android sqliteopenhelper

我在应用程序中创建了一个函数,用于检查数据库中的用户名和密码,但是我收到了该错误

07-02 00:31:09.619: E/Cursor(345): Finalizing a Cursor that has not been deactivated or closed. database = /data/data/sbn.project.gp/databases/users, table = null, query = SELECT name,password FROM users WHERE name='khaled'and password='1234'

这是我的代码

public Boolean check(String nameS, String passwordS) {
        // TODO Auto-generated method stub

        Cursor c = null;
        Boolean check = true;

        c = ourDatabase.rawQuery("SELECT name,password FROM users WHERE name='"
                + nameS + "'" + "and password='" + passwordS + "'", null);

        if (c.getCount() > 0) {
            check = false;
            return check;
        }
        c.close();


        return check;
    }

1 个答案:

答案 0 :(得分:1)

这是因为如果check为false,你没有关闭光标,而是这样做:

public Boolean check(String nameS, String passwordS) {
        Cursor c = null;
        Boolean check = true;

        c = ourDatabase.rawQuery("SELECT name,password FROM users WHERE name='"
                + nameS + "'" + "and password='" + passwordS + "'", null);

        if (c.getCount() > 0) {
            check = false;
        }
        c.close();
        return check;
    }