2
this.tModel = new AdvancedMibTableModel(); 
this.table = new JTable(this.tModel);
this.tModel.addRow(new Object[]{"sysLocation","1.3.6.1.2.1.1.6","0",""});

when running the above code the following exception occured.

java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
at java.util.Vector.elementAt(Unknown Source)
at javax.swing.table.DefaultTableModel.justifyRows(Unknown Source)
at javax.swing.table.DefaultTableModel.insertRow(Unknown Source)
at javax.swing.table.DefaultTableModel.addRow(Unknown Source)
at javax.swing.table.DefaultTableModel.addRow(Unknown Source)

what i am doing wrong here? what is the actual problem? can anyone suggest a solution? i tried both addRow() and insertRow() but the same problem occured.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Nikhil
  • 2,857
  • 9
  • 34
  • 58

2 Answers2

2

exceptions is pretty clear

at java.util.Vector.elementAt(Unknown Source)

v.s.

this.tModel.addRow(new Object[]{"sysLocation","1.3.6.1.2.1.1.6","0",""});

  • have to create Vector<Object> instead of new Object[]

  • for better help sooner post an SSCCE

mKorbel
  • 109,525
  • 20
  • 134
  • 319
1

Did you add the columns to Model?

If not, you should to avoid this exception.

You can add columns to model as follows:

TableColumn location = new TableColumn();
// ...
// set location fileds i.e. header etc.
// ...
this.tModel.addColumn(location); 
Azodious
  • 13,752
  • 1
  • 36
  • 71
  • the colomns are added in the customised model "AdvancedMibTableModel" – Nikhil Oct 31 '12 at 06:56
  • the model is already set with 4 colomns. in the above code i want to set that model to the table and want to add rows in it. but cant add beacause of this exception – Nikhil Oct 31 '12 at 07:03