Finalizar un cursor no se ha desactivado

I have created a function in an application that checks for username and password from the database but i get that error

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'

aqui esta mi codigo

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

preguntado el 01 de julio de 12 a las 22:07

I think you need to have that c.close() before the return in your if statement, even if the cursor is empty. -

1 Respuestas

It's because you didnt close the cursor if check is false , do this instead :

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

Respondido 01 Jul 12, 23:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.