java - how to store string data into integer array from sqlite for android -
i want convert sqlite data integer array.
public integer[] getch() { sqlitedatabase database = this.getreadabledatabase(); cursor cursor = database.rawquery("select sum(sales) sales group outlet_code order ordered_date", null); // string[] array = new string[crs.getcount()]; int columnindex = 3; integer[] in = new integer[cursor.getcount()]; if (cursor.movetofirst()) { (int = 0; < 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 error :
couldn't read row 0, col 3 cursorwindow. make sure cursor initialized correctly before accessing data it
why using columnindex = 3
, sql query return 1 column i.e sum(sales)
, should set columnindex
value 0
try this
public integer[] getch() { sqlitedatabase database = this.getreadabledatabase(); cursor cursor = database.rawquery("select sum(sales) sales group outlet_code order ordered_date", null); // string[] array = new string[crs.getcount()]; int columnindex = 0; integer[] in = new integer[cursor.getcount()]; if (cursor.movetofirst()) { (int = 0; < cursor.getcount(); i++) { in[i] = cursor.getint(columnindex); cursor.movetonext(); } } cursor.close(); return in; }
hope helps
Comments
Post a Comment