Thursday, 15 January 2015

Android for-loop getting stuck in endless loop -



Android for-loop getting stuck in endless loop -

i have jsonarray of jsonobjects in each of string key "kind". i'm trying loop through jsonarray , organize them "kind" utilize fill seperatedlistadapter. trying accomplish structure

{ communications[ { "header":"kind" communications[ {} {} {} {} ] } { "header":"kind" communications[ {} {} {} {} ] } ] }

the problem i'm having loop have created accomplish gets stuck in endless loop , crashes application. know going wrong this?

here's code know gets stuck in loop runs log "1" 1000 times though know there's 5 things in array i'm passing in.

for(int = 0; < communicationsfromfile.length(); i++){ jsonobject communication = communicationsfromfile.getjsonobject(i); log.v("communications", "kind = " + communication.getstring("kind")); log.v("communications", "newcomarray = " + newcomarray); if(newcomarray.length() != 0){ log.v("communications", "newcomarray isnotempty"); for(int = 0; < newcomarray.length();a++){ jsonobject iteminarray = newcomarray.getjsonobject(a); jsonarray communicationsforkind = iteminarray.getjsonarray("communications"); log.v("communications", "1"); if(iteminarray.getstring("header").equals(communication.getstring("kind"))){ log.v("communications", "header exists"); communicationsforkind.put(communication); iteminarray.put("communications", communicationsforkind); newcomarray.put(iteminarray); }else{ log.v("communications", "header not exist"); jsonobject additeminarray = new jsonobject(); jsonarray addarraytoitem = new jsonarray(); addarraytoitem.put(communication); additeminarray.put("header", communication.getstring("kind")); additeminarray.put("communications", addarraytoitem); newcomarray.put(additeminarray); } } }else{ jsonobject additeminarray = new jsonobject(); jsonarray addarraytoitem = new jsonarray(); addarraytoitem.put(communication); additeminarray.put("header", communication.getstring("kind")); additeminarray.put("communications", addarraytoitem); newcomarray.put(additeminarray); } }

in each iteration of inner loop, set new objects in newcomarray. status a < newcomarray.length() satisfied because a , array length both grow @ same rate.

android

No comments:

Post a Comment