Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1 error on my calendar program : My program compiles correctly but I get the same message when I try and run it.


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package displaycalendars;

import java.util.Calendar;
import java.util.GregorianCalendar;

public class DisplayCalendars {

	public static void main(String[] args){
		Calendar calendar = new GregorianCalendar
				(Integer.valueOf(args[1]),
				Integer.valueOf(args[0])-1,1);
		
		printHeader(calendar);
		printData(calendar);			
		}
	public static void printHeader(Calendar calendar){
	
		int month = calendar.get(Calendar.MONTH)+1;
		
		String monthName = "";
		
		switch(month){
		
		case 1: monthName="January";
		break;
		case 2: monthName="February";
		break;
		case 3: monthName="March";
		break;
		case 4: monthName="April";
		break;
		case 5: monthName="May";
		break;
		case 6: monthName="June";
		break;
		case 7: monthName="July";
		break;
		case 8: monthName="August";
		break;
		case 9: monthName="September";
		break;
		case 10: monthName="October";
		break;
		case 11: monthName="November";
		break;
		case 12: monthName="December";
		break;
		}
		System.out.println(" "+monthName+ ", " +calendar.get(Calendar.YEAR));
		System.out.println("--------------------");
		System.out.println("Sun Mon Tue Wed Thu Fri Sat");
		}
	public static void printData(Calendar calendar){
		int dayinWeek=calendar.get(Calendar.DAY_OF_WEEK);
		
		for (int i = 1; i< (dayinWeek); i++)
			{
			System.out.print(" ");
			}
		for (int i = 1; i <
			(Calendar.DATE); i++){
		System.out.print("\n");
		calendar.add(Calendar.DATE,1);
		}
		System.out.printf("%4d",calendar.get(Calendar.DATE));
	}
}

				
			

	

