Hi there,
I got a NullPointerException when I tried to get all the agenda that are recorded in my SQLite database.
The insert works well, I create a Toast with the ID which is returned, and it increment normally.
For information, I don't call getAllAgenda() in my main activity but in a secondary one... with this code :
Any ideas ?
Thanx a lot !
I got a NullPointerException when I tried to get all the agenda that are recorded in my SQLite database.
The insert works well, I create a Toast with the ID which is returned, and it increment normally.
Code:
public List<Agenda> getAllAgenda() {
List<Agenda> agendas = new ArrayList<Agenda>();
Cursor cursor;
try {
cursor = bdd.query(TABLE_AGENDA,
new String[] {COL_ID, COL_INTITULE, COL_DATE, COL_HEURE}, null, null, null, null, null);
if ( cursor.moveToFirst() ) {
while (!cursor.isAfterLast()) {
Agenda agenda = cursorToAgenda(cursor);
agendas.add(agenda);
cursor.moveToNext();
}
}
cursor.close();
} catch (Exception e){
Log.d("AGENDA DAO", e.toString() );
}
return agendas;
}
Code:
public class ListeActivity extends ListActivity {
private AgendaDAO agendaDAO;
private SimpleCursorAdapter dbAdapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_liste);
ListView listView = (ListView)findViewById(android.R.id.list);
agendaDAO = new AgendaDAO(this);
agendaDAO.open();
try {
List<Agenda> agendas = agendaDAO.getAllAgenda();
Log.d("NB AGENDA",Integer.toString(agendas.size()));
ArrayAdapter<Agenda> adapter = new ArrayAdapter<Agenda>(this,
android.R.layout.simple_list_item_1, agendas);
listView.setAdapter(adapter);
} catch(Exception e){
Log.d("EXCEPTION",e.toString());
}
agendaDAO.close();
}
}
Thanx a lot !