ArrayIndexOutOfBoundException

HI All

Following is a code snippet of my table model, it bound the value of a vector to the table.

publicint getColumnCount(){return 1;}

publicint getRowCount(){return results.size();}

public String getColumnName(int column ){

return"Report Name";

}

public Class getColumnClass(int i ){

return String.class;

}

public Object getValueAt(int row,int col ){

return results.get( row );

}

/*

* Update changes to add Database records

* to the table*/

publicvoid fireTableChanged(){

for(int i = 0; i < results.size() ; i++ ){

getValueAt( i, 0 );

}

}

/*public void valueChanged( ListSelectionEvent event ) {

if( event.getSource() ==)

}*/

I wrote a listener valueChanged function, the function prints the selected row and column correctly, but when using getValueAt(table.getSelectedRow(), table.getSelectedColumn())

an ArrayIndexOutOfBoundException

is thrown....

Any help please?

[2178 byte] By [jotnartaa] at [2007-10-3 9:24:25]
# 1

I think that in the

public Object getValueAt( int row, int col ) {

return results.get( row );

}

you should check if the row and col are inside your table and write something like this

public Object getValueAt( int row, int col ) {

if (row >= results.capacity()|| row< 0 || col!= 0) {

return "";}

return results.get( row );

}

since when you change the data of the table, the selectedRow and selectedCol values stay the same.

Ksushaa at 2007-7-15 4:38:22 > top of Java-index,Desktop,Core GUI APIs...
# 2
It was very hard to detect some error like that,THANK YOU VERY VERY much buddy, It's worked fine now.Jotnarta
jotnartaa at 2007-7-15 4:38:22 > top of Java-index,Desktop,Core GUI APIs...
# 3
Anytime:)I'm glad I was able to help
Ksushaa at 2007-7-15 4:38:22 > top of Java-index,Desktop,Core GUI APIs...