ERROR:Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

1.3k views Asked by At

Am trying to design a calendar using a j table, table model which uses and array list and the Gregorian calendar. i implemented the setValueAt() in the table model that i use to draw the calendar. but when i run the programme, i get the message:

Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0. 

Can any one help me to fix this error?

    GregorianCalendar cal = new GregorianCalendar(year, month, 1);
    nod = cal.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
    som = cal.get(GregorianCalendar.DAY_OF_WEEK);

    //Draw calendar
    for (int i=1; i<=nod; i++){
        int row = (i+som-2)/7;
        int column  =  (i+som-2)%7;
        jTable1.getModel().setValueAt( i, row, column);

    }
}

@Override
public void setValueAt(Object aValue,  int rowIndex, int columnIndex){
    data1.get(rowIndex).set(columnIndex, aValue.toString());
}

Update

I initialized data1 by passing a two dimensional arraylist argument to constructor of the tablemodel.

ArrayList <String> column1 = new ArrayList(); 
ArrayList<ArrayList<String>> data1 = new ArrayList(); 
public mymodel(ArrayList<ArrayList<String>> d, ArrayList<String> c) { 
    this.column1 = c; 
    this.data1 = d;
}
0

There are 0 answers