android - Loading listview using SharedPreferences throwing OutofMemoryError -


i using edittext , button in mainactivity, onclicking want add text listview properly.

i saving using sharedpreferences,so when go mainactivity or restart app ,it automatically loads listview,but on clicking button ,i outofmemoryerror @ line:

   arraycars.add(new car(pred.getstring("value["+i+"]", ""),"green",3455)); 

listview code:

       arraylist<car> arraycars; listview listviewcars; string venname; sharedpreferences pred; sharedpreferences.editor speditor; static int count = 0;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      arraycars=new arraylist<car>();      system.out.println("count is"+count);     pred = getsharedpreferences("place", context.mode_private);        speditor = pred.edit();        count = pred.getint("countd",count);         if(count > 0){            for(int = 0; < count; i++){                 arraycars.add(new car(pred.getstring("value["+i+"]",  ""),"green",3455));           count++;            }           }        listviewcars = (listview) findviewbyid(r.id.list_cars);     listcarsadapter adapter = new listcarsadapter(this, arraycars);     listviewcars.setadapter(adapter);     listviewcars.setonitemclicklistener(this);        try{         bundle bundle = getintent().getextras();          venname = bundle.getstring("r");      }catch(exception e){}          if(venname!=null){         speditor.putstring("value["+count+"]", venname);         speditor.apply();         arraycars.add(new car(pred.getstring("value["+count+"]", ""),"red",3444));         count += 1;         speditor.putint("countd", count);         adapter.notifydatasetchanged();         }        } 

ps: using custom listview

count = pred.getint("countd",count);     if(count > 0){        for(int = 0; < count; i++){             arraycars.add(new car(pred.getstring("value["+i+"]",  ""),"green",3455));       count++;        }     } 

in above code increasing count 1 each time never ends loop repeat untill throw exception.

to avoid delete count++;

hope helps you.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -