错误:线程“AWT-EventQueue-0”中的异常java.lang.IndexOutOfBoundsException:索引:0,大小:0

时间:2014-11-17 18:04:11

标签: java arraylist tablemodel

我试图使用j表,使用表格模型和数组列表以及格里高利历来设计日历。我在用于绘制日历的表模型中实现了setValueAt()。但是当我运行程序时,我收到消息:

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

任何人都可以帮我修复此错误吗?

    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());
}

更新

我通过将二维arraylist参数传递给tablemodel的构造函数来初始化data1

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 个答案:

没有答案