I have a cursor reading a SQLite DB and getting a lot of columns, I am storing these columns in a lot of arrays
private ArrayList<String> column1,column2,column3,column4, ... column n;
public getCursorData(Cursor cursor){
if(cursor.moveToFirst()){
do{
column1.add(Cursor.getString("column1"));
column2.add(Cursor.getString("column2"));
column3.add(Cursor.getString("column3"));
column4.add(Cursor.getString("column4"));
...
columnn.add(Cursor.getString("columnN"));
}while(cursor.moveToNext());
}
}
I am looking for a way to store them in a single object (or array, or List, or something), but I can not figure it how to do it
private Object[] object;
public getCursorData(Cursor cursor){
if(cursor.moveToFirst()){
int i=0;
do{
for(int f=0;f<cursor.getColumnCount();f++){
object[i].put(cursor.getColumnName(i), cursor.getString(i)); // I don't know what I am doing!
}
i++;
}while(cursor.moveToNext());
}
}
A different attempt using arrays, where each column is an integer number.
private String[][] data;
public getCursorData(Cursor cursor){
if(cursor.moveToFirst()){
int i=0;
do{
for(int f=0;f<cursor.getColumnCount();f++){
data[i][f]=cursor.getString(f); // this is line 30
}
i++;
}while(cursor.moveToNext());
}
}
This last attempt fails throwing the following error java.lang.NullPointerException: Attempt to read from null array on line 30 (I marked this line in a comment on the code)