Search code examples
javaswingjtabledefaulttablemodelindexoutofboundsexception

ArrayIndexOutOfBoundsException when adding row in jtable


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.


Solution

  • 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