0

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

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;
    }
4

1 回答 1

1

这是因为如果检查为假,您没有关闭光标,请改为执行以下操作:

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;
    }
于 2012-07-01T22:16:02.510 回答