java - While loop stack overflow -


i use method, , while loop stack overflow. no error message or crash. got in log cat:

05-18 20:17:16.528: w/inputeventreceiver(19831): attempted finish input event input event receiver has been disposed. 

when put code in while boolean:

data.numberofsamedaterows(selectedday) != 0 

the loop fine. when use below got stack overflow.

if(data.numberofsamedaterows(selectedday) != 0)                 i=0;             else                 i++; 

thank helping :)

here code:

databasemain data = new databasemain(this);     data.open();      simpledateformat dateformatter = new simpledateformat("d-mmmm-yyyy");     string datewanted = getcorrectdate(removespinner);      date wanteddate = new date();     int = 0;      try {         wanteddate = dateformatter.parse(datewanted);         } catch (parseexception e) {             e.printstacktrace();     }      calendar mycal = new gregoriancalendar();     mycal.settime(wanteddate);     date newdate = mycal.gettime();      string selectedday = dateformatter.format(newdate);      if(datewanted.equals("all") == false){        do{      if(data.numberofsamedaterows(selectedday) != 0)             i=0;         else             i++;      mycal.add(calendar.day_of_year, 7);          newdate = mycal.gettime();       selectedday = dateformatter.format(newdate);      }     while(i < 5);   public int numberofsamedaterows(string date){          int = 0;         string[] columns = new string[]{column_date};         cursor c = ourdatabase.query(table_name, columns, column_date + "= '" + date + "'", null, null, null, null);      if(c.getcount() >= 1)         (c.movetofirst(); !c.isafterlast(); c.movetonext()){             i++;         }         return i;        } 

looks infinite loop. never ending , causing stack overflow.

do{  if(data.numberofsamedaterows(selectedday) != 0)         i=0;     else         i++;  mycal.add(calendar.day_of_year, 7);      newdate = mycal.gettime();   selectedday = dateformatter.format(newdate);  } while(i < 5); 

you have while set < 5 in statement keep setting = 0.

this cause set 0 every time never reach i=5 , stuck in there consuming resources. highest ever reach 1.

i recommend setting = 0 prior statement isn't within loop.

fix , work.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -