when I create an instance of the ticket class and call the method print ticket, it comes up with this,
sss.jpg
this is my codeimport java.util.ArrayList; /** * lucky dip lottery ticket system. * * @author (Daniel Prempeh) * @version 1.1 2013 */ public class Ticket { //array list store instances of number class private ArrayList<Numbers> lottoticket; private int qty; public Ticket(int numOfLines) { lottoticket = new ArrayList<Numbers>(); //needs a loop for(int i=0; i<qty; i++) { lottoticket.add(new Numbers()); } } //print out ticket public void printTicket() { //printout header of ticket System.out.println("******************************"); System.out.println("** **"); System.out.println("** Ticket **"); System.out.println("** **"); System.out.println("******************************"); //detail //needs a loop lottoticket.get(0).print(); //printout footer of ticket System.out.println("******************************"); } }
the fault occurs with lottoticket.get(0).print();
and on the terminal it says...
java.lang.indexoutofboundsexception: index 0, size 0
at java.util.arraylist.rangecheck(arraylist.java:604)
at java.util.arraylist.get(arraylist.java:382)
at ticket.printticket(ticket.java:35)