-1
dm = (DefaultTableModel) jTable2.getModel();
int row = dm.getRowCount();
getTable obj1 = new getTable(); 
System.out.println("list size " + stu.size());
for (int i = 0; i <= stu.size(); i++ ) {
    obj1 = (getTable)stu.get(i);
    dm.setValueAt(obj1.getStrName(),row , 0);
    dm.setValueAt(obj1.getStrFname(),row , 1); 
    dm.setValueAt(obj1.getRoll_num(),row , 2);
    dm.setValueAt(obj1.getAddr1(),row , 3);
    dm.setValueAt(obj1.getAddr2(),row , 4);
    dm.setValueAt(obj1.getPhoneNumber(),row , 5);
    dm.setValueAt(obj1.getEmail(),row , 6);
    dm.setValueAt(obj1.getDept(),row , 7);
}

I am new at coding I just got stuck on this problem for quite sometime now, What am I doing wrong here?

Pang
  • 9,564
  • 146
  • 81
  • 122
  • 2
    Possible duplicate of [What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it?](http://stackoverflow.com/questions/5554734/what-causes-a-java-lang-arrayindexoutofboundsexception-and-how-do-i-prevent-it) – Frakcool Sep 21 '16 at 18:02
  • Welcome to Stack Overflow, please take the [tour], then learn [ask] a good question which involves a [mcve] and don't forget to post your exception here and indent your code correctly – Frakcool Sep 21 '16 at 18:03
  • @Frakcool Thanks and will work on it. – Saifi Haq Sep 21 '16 at 18:07

2 Answers2

3

ArrayList.size() returns the no of elements in the list.

Also ArrayList starts with the index 0.

So to iterate through n events in an ArrayList we have to iterate till ArrayList[n-1].

So avoid the <= condition in loop and put <.

Frakcool
  • 10,915
  • 9
  • 50
  • 89
Akhil Job
  • 419
  • 6
  • 18
1

This ArrayIndexOutOfBoundsException: 0 means that the index 0 is not a valid index for your array, which in turn means that your array is empty.

Volodymyr
  • 6,393
  • 4
  • 53
  • 84