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.

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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

2 Comments

the colomns are added in the customised model "AdvancedMibTableModel"
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.