I want to convert the sqlite data into integer array.
public Integer[] getch() {
SQLiteDatabase database = this.getReadableDatabase();
Cursor cursor = database.rawQuery("SELECT sum(sales) FROM sales group by outlet_code order by ordered_date", null);
// String[] array = new String[crs.getCount()];
int columnIndex = 3;
Integer[] in = new Integer[cursor.getCount()];
if (cursor.moveToFirst())
{
for (int i = 0; i < cursor.getCount(); i++)
{
in[i] = cursor.getInt(columnIndex);
cursor.moveToNext();
}
}
cursor.close();
return in;
}
I need result in following format:
int[] income = { 2000,2500,2700,3000,2800,3500,3700,3800, 0,0,0,0};
Integer[] income = controller.getch();
I'm getting the error :
Couldn't read row 0, col 3 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it
in[i] = cursor.getInt(0);