I've been trying to implement a add function in the ListToDo class using three other classes Task, Date and Time. However once the user inputs the data into the add function the following happens;
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1, Size: 0 at java.util.ArrayList.rangeCheckForAdd(ArrayList.java:665) at java.util.ArrayList.add(ArrayList.java:477) at ToDoList.addTask(ListToDo.java:213) at ToDoList.displayMenu(ListToDo.java:272) at ToDoList.main(ListToDo.java:188)
class ListToDo{
    private ArrayList<Task> list;
    public static void main(String[] args){
    menu(); // displays menu to user
}
public ListToDo(){
    list = new ArrayList<Task>();
}
public void add(Task newTask){      
    list.add(newTask.getTaskID(), newTask);
}
public void print(Task[] newTask){
    list.addAll(Arrays.asList(newTask));
    list.size();
    menu();
}
private static void menu(){
    Scanner input = new Scanner(System.in);
    ListToDo toDoList = new ListToDo();
    System.out.println("1: Add a task");
    int option=input.nextInt();
    switch(option){ // selection statement 
        case 1: //1: Add a task
        System.out.print("Please input the new task title: ");
        String title=input.next();
        System.out.print("Please input the new task date (dd mm yyyy): ");
        int day=input.nextInt();
        int month=input.nextInt();
        int year=input.nextInt();
        System.out.print("Please input the starting time (hh mm): ");
        int hour=input.nextInt();
        int min=input.nextInt();
        System.out.print("Please input the location: ");
        String location=input.next();
        Time time = new Time(hour, min);
        Date date = new Date(day, month, year);         
        Task newTask = new Task(time,date,title,location);
        toDoList.add(newTask);
        System.out.println("Task "+newTask.getTaskID()+" is added. The To-Do list is follows:");
        Task[] newTask1 = new Task[0];
        newTask1[0] = new Task(time,date,title,location);
        toDoList.print(newTask1);
        menu();
        break;
        default: //ERROR 
        System.out.println("ERROR! Please select an action listed below:");
        menu();
    } 
}
}
 
     
    