This is my method, I have gone through every out of bounds exception but cant work out whats going on. This is not the same as other questions as i have tried all the logical steps issued from other questions
private void gettablecount(TableModel mod){
int r = mod.getRowCount()+1;
int c = mod.getColumnCount()+1;
String[][] ps = new String[r][c];
for (int rw = 0;rw <=r;rw++){
for (int cl = 0;cl<=c;cl++){
ps[rw][cl] = mod.getValueAt(rw, cl).toString();
System.out.print(ps[rw][cl] + " ");
}
System.out.println();
}
}
my table model mod has r = 133 rows and c = 249 columns, I then try and put this into a 2d array, and no matter what i try i keep getting out of bounds exceptions, please can someone provide some help? The errors i have got is x>=x or -1, or just x, in trying to work this out. Should be quite straight forward but i dont know whats going on.
I have just tried this:
private void gettablecount(TableModel mod){
int r = mod.getRowCount()+1;
int c = mod.getColumnCount()+1;
String[][] ps = new String[r][c];
for (int rw = 0;rw <r;rw++){
for (int cl = 0;cl<c;cl++){
ps[rw][cl] = mod.getValueAt(rw, cl).toString();
System.out.print(ps[rw][cl] + " ");
}
System.out.println();
}
}
But i get the stacktrace:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 249 >= 249 at java.util.Vector.elementAt(Vector.java:474)
Here is my vector where line 474 is, i have annotated line 474
public synchronized E elementAt(int index) {
if (index >= elementCount) {
//line 474 below
throw new ArrayIndexOutOfBoundsException(index + " >= " + elementCount);
}
return elementData(index);
}