Todas as vezes que tento iniciar a aplicação, eu recebo esse erro: java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.alura.agenda/br.com.alura.agenda.ListaAlunosActivity}: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow.Make sure the Cursor is initialized correctly before accessing data from it.
Aqui tá o método em questão:
public List<Aluno> buscaAluno(){
String sql = "SELECT * FROM alunos;";
SQLiteDatabase db = getReadableDatabase();
Cursor c = db.rawQuery(sql, null);
List<Aluno> alunos = new ArrayList<>();
while (c.moveToNext()){
Aluno aluno = new Aluno();
aluno.setId(c.getLong(c.getColumnIndex("id")));
aluno.setNome(c.getString(c.getColumnIndex("nome")));
aluno.setTelefone(c.getString(c.getColumnIndex("telefone")));
aluno.setEndereco(c.getString(c.getColumnIndex("endereco")));
aluno.setTwitter(c.getString(c.getColumnIndex("twitter")));
aluno.setSnapchat(c.getString(c.getColumnIndex("snapchat")));
aluno.setFacebook(c.getString(c.getColumnIndex("facebook")));
aluno.setInstagram(c.getString(c.getColumnIndex("intagram")));
aluno.setNota(c.getDouble(c.getColumnIndex("nota")));
alunos.add(aluno);
}
c.close();
return alunos;
}
E aqui a activity:
AlunoDAO dao = new AlunoDAO(this);
List<Aluno> alunos = dao.buscaAluno();
dao.close();
final ListView ListaAlunos = (ListView) findViewById(R.id.lista_alunos);
ArrayAdapter<Aluno> adaptador = new ArrayAdapter(this, R.layout.support_simple_spinner_dropdown_item, alunos);
Att, Obrigado