I want to ask about how to store data retrieved from a cursor object in an array. I am unable to do that and getting an null pointer exception because I am not able to initialize the size of the array? Where do I write that code and store all the data retrieved from cursor object in an array. Please I am unable to do that.
My code for retrieving the data from the cursor is below.
if (c != null ) {
if (c.moveToFirst()) {
do {
firstName = c.getString(c.getColumnIndex("FirstName"));
int age = c.getInt(c.getColumnIndex("Age"));
//results.add("Name: " + firstName + ",Age: " + age);
}while (c.moveToNext());
}
}
The problem is, that you have two values that you want to store. So a normal array will not solve the problem. You can use an ArrayList of a custom class. Or you use the Pair class.
Try this: