android - Sqlite ArrayList<Float> query run with AsyncTask -


i trying create chart app , having trouble load data chart. gives me out of memory error. have been trying have sqlite query run in background thread using asynctask. tried not able create correctly. post code here , hope can me on this. many thanks!!!!

here error message:

     java.lang.outofmemoryerror: failed allocate 103059952 byte allocation 4194304 free bytes , 53mb until oom                                                                      @ java.util.arraylist.add(arraylist.java:118)                    

here part of code provide me data source. pulling data sqlite database. query works. tested. need write code run query in background thread asynctask.

     public arraylist<float> ydata(){     arraylist<float> ynewdata=new arraylist<float>();     sqlitedatabase db=this.getreadabledatabase();     string sql="select sum("+ tabledata.tableinfo.col_s4_amt+") monthpiechartcategoryvalues,c."+ tabledata.tableinfo.col_c2_description+" category "+ tabledata.tableinfo.database_table_spending+" s join "+ tabledata.tableinfo.database_table_items+" on i."+ tabledata.tableinfo.col_i1_itemid+"=s."+ tabledata.tableinfo.col_s3_itemid+ " join "+ tabledata.tableinfo.database_table_category+" c on c."+ tabledata.tableinfo.col_c1_categoryid+"=i."+ tabledata.tableinfo.col_i3_categoryid + " strftime('%y',"+ tabledata.tableinfo.col_s2_spending_dt+")=strftime('%y',date('now')) , strftime('%m',"+ tabledata.tableinfo.col_s2_spending_dt+")=strftime('%m',date('now')) group c."+ tabledata.tableinfo.col_c2_description+" order category  desc";     cursor cursor=db.rawquery(sql,null);     for(cursor.movetofirst();!cursor.isafterlast();cursor.movetolast()){         ynewdata.add(cursor.getfloat(cursor.getcolumnindex(monthpiechartcategoryvalues)));     }     cursor.close();     return ynewdata;  } 

as selvin says, loop run infinite times since moving last element after every run of loop. try :

cursor.movetofirst(); while(!cursor.isafterlast()) {     ynewdata.add(cursor.getfloat(cursor.getcolumnindex(monthpiechartcategoryvalues)));     cursor.movetonext(); } cursor.close(); 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -