Skip to content Skip to sidebar Skip to footer

Android Calendar Illegalargumentexception When Calendar.month Set To 1

The code below works fine except when calendar.MONTH set to 1 (Feb),and I do not know why ? Thanks. Calendar calendar = Calendar.getInstance(); calendar.setLenient(false);

Solution 1:

You're getting the current date in getInstance. Then you're setting the month to February. The problem is that today is the 30th. February has 28 days. That's an illegal combo. Change the day to a valid day, then change the month.

Solution 2:

Change field names in set method

calendar.YEARto   Calender.YEAR
calendar.MONTHto  Calender.MONTH

They are static fields and should be referrred with the Class

Post a Comment for "Android Calendar Illegalargumentexception When Calendar.month Set To 1"