'Android Studio, Java: getCount of Cursor returns 0 after checkUser function with newly created User

I have an in-memory SQLite DB and created a row with an ID, username and password in runtime. That insert returns 1.

Afterwards I run the following function to check the user credentials of the created user with those that are in the input fields, which are the exact same credentials used for the created user above. (basically, I check if the user is already existing, if not, I use the credentials entered to create the user and instantly check to authenticate the login)

The getCount at the end always returns 0 and I don't know why. Debugger shows the correct credentials for username and password, and I'm starting to run out of time... Final exam project...

public boolean checkUser(String username, String password) {
        String[] columns = new String[]{
                COL_USERNAME,
                COL_PASSWORD
        };
        SQLiteDatabase db = this.getReadableDatabase();
        String selection = COL_USERNAME + " = ?" + " AND " + COL_PASSWORD + " = ?";
        String[] selectionArgs = {username, password};

        Cursor c = db.query(
                T_USER,
                columns,
                selection,
                selectionArgs,
                null,
                null,
                null);
        int cursorCount = c.getCount();
        c.close();
        db.close();
        if (cursorCount > 0) {
            return true;
        }
        return false;
    }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source