tags:

views:

8

answers:

0

Hello,

i have trouble with a piece of code that runs fine on 99% of installations, but leads to an infinite loop on a few HTC Desire handsets.

What I'm trying to do is to create a list of months for which data is available. I start from the first date for which data is available and then use a loop until i reach the present.

Here is the code (simplified):

    GregorianCalendar today = new GregorianCalendar();
    GregorianCalendar xCal = new GregorianCalendar();
    xCal.setTime(startDate);
    xCal.set(GregorianCalendar.DAY_OF_MONTH, resetDay); // resetDay = end of billing period
    while(xCal.before(today))
    {
        MonthObject xObj = new MonthObject(); // Create object to hold information
        xObj.setTimestamp(xCal.getTimeInMillis()); // Save timestamp for start of period
        xObj.setFromDate(xCal.getTime());  // Save date for start of period
        xCal.add(GregorianCalendar.MONTH, 1); // Increment by 1 month
        xCal.set(GregorianCalendar.DAY_OF_MONTH, resetDay); // set to end of billing period
        xCal.set(Calendar.HOUR_OF_DAY, 0); // make sure it's midnight
        xCal.set(Calendar.MINUTE, 0);
        xCal.set(Calendar.SECOND, 0);
        xCal.set(Calendar.MILLISECOND, 0);
        xObj.setToDate(xCal.getTime()); // Save timestamp for end of period
        xObj.setToTimestamp(xCal.getTimeInMillis()); // Save date for end of period
    Log.v("NetworkCheck", "Added MonthObject - " + xObj.fromDate.toGMTString() + " to " + xObj.toDate.toGMTString());
        dates.add(xObj); // Add to collection
        xObj = null;
    }
    xCal = null;
    today = null;

So, on 99% of handsets this gives the desired result (list of months). On a few handsets, however, i get this output:

D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to 30 Aug 2010 22:00:00 GMT
D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to 30 Aug 2010 22:00:00 GMT
D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to 30 Aug 2010 22:00:00 GMT
D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to 30 Aug 2010 22:00:00 GMT
D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to 30 Aug 2010 22:00:00 GMT
D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to 30 Aug 2010 22:00:00 GMT
D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to 30 Aug 2010 22:00:00 GMT
D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to 30 Aug 2010 22:00:00 GMT
D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to 30 Aug 2010 22:00:00 GMT
D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to 30 Aug 2010 22:00:00 GMT
D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to 30 Aug 2010 22:00:00 GMT
D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to 30 Aug 2010 22:00:00 GMT
D/NetworkCheck( 2311): Added MonthObject - 30 Aug 2010 22:00:00 GMT to 30 Aug 2010 22:00:00 GMT

and i have absolutely no idea why this is. Has anyone else come across a similar problem?

Thanks!

Andreas