fetch all records from an sqlite column

0

I need to save the names of the users table in a list and save them in an ArrayList. I did this:

 public List<String> buscarUsuarios() {
    List<String> nomes = new ArrayList<String>();
    String selectQuery = "select nome from usuarios";
    Cursor cursor = db.rawQuery(selectQuery, null);


    if (cursor.getCount() > 0) {
        cursor.moveToFirst();
        do {

            cursor.moveToFirst();
            String nomeString = cursor.getString(cursor.getColumnIndex("nome"));

            StringBuilder conversor = new StringBuilder();
            conversor.append(nomeString);

            nomes.add(conversor.toString());

        } while (cursor.moveToNext());

    }
    return nomes;
}

But it's giving infinite looping Can anyone help me?

    
asked by anonymous 05.07.2017 / 20:40

1 answer

3

You are moving the cursor to the first record all the time.

Remove cursor.moveToFirst(); from within do

    
05.07.2017 / 20:49