title: Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
body: <p>The titled exception throwing in a table when I run a method where a row might be deleted there and after that when I try to clear the table rows. Can any one explain me why is this happening? I am not an expert in java. </p>
  
  <p>Exception:</p>
  
  <pre><code>Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
          at java.util.Vector.elementAt(Vector.java:430)
          at javax.swing.table.DefaultTableModel.getValueAt(DefaultTableModel.java:632)
          at javax.swing.JTable.getValueAt(JTable.java:2652)
          at classes.RowListener.displayRowValues(RowListener.java:40)
          at classes.RowListener.valueChanged(RowListener.java:32)
          at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:167)
          at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:147)
          at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:194)
          at javax.swing.DefaultListSelectionModel.removeIndexInterval(DefaultListSelectionModel.java:660)
          at javax.swing.JTable.tableRowsDeleted(JTable.java:4460)
          at javax.swing.JTable.tableChanged(JTable.java:4363)
          at javax.swing.table.AbstractTableModel.fireTableChanged(AbstractTableModel.java:280)
          at javax.swing.table.AbstractTableModel.fireTableRowsDeleted(AbstractTableModel.java:245)
          at javax.swing.table.DefaultTableModel.setNumRows(DefaultTableModel.java:304)
          at javax.swing.table.DefaultTableModel.setRowCount(DefaultTableModel.java:322)
          at saraentry.MainFace.clearTable(MainFace.java:73)
          at saraentry.MainFace.jButton1ActionPerformed(MainFace.java:578)
          at saraentry.MainFace.access$1200(MainFace.java:32)
          at saraentry.MainFace$14.actionPerformed(MainFace.java:424)
          at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
          at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
          at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
          at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
          at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
          at java.awt.Component.processMouseEvent(Component.java:6038)
          at javax.swing.JComponent.processMouseEvent(JComponent.java:3260)
          at java.awt.Component.processEvent(Component.java:5803)
          at java.awt.Container.processEvent(Container.java:2058)
          at java.awt.Component.dispatchEventImpl(Component.java:4410)
          at java.awt.Container.dispatchEventImpl(Container.java:2116)
          at java.awt.Component.dispatchEvent(Component.java:4240)
          at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
          at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986)
          at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
          at java.awt.Container.dispatchEventImpl(Container.java:2102)
          at java.awt.Window.dispatchEventImpl(Window.java:2429)
          at java.awt.Component.dispatchEvent(Component.java:4240)
          at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
          at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
          at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
          at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
          at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
          at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
          at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
  BUILD SUCCESSFUL (total time: 20 seconds)
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>public class MainFace extends javax.swing.JFrame {
  
  public String selectedRaw, tColSqNum, tColJobNo, tColDecName, tColDate;
  String pendingDate, getTDate;
  
  /** Creates new form MainFace */
  public MainFace() {
      theme.theme();
      initComponents();
      newJob.setMnemonic(KeyEvent.VK_N);
      setLocationRelativeTo(null);
      DefaultTableModel tm = (DefaultTableModel) jTable1.getModel();
      tm.setRowCount(0);
      ListSelectionModel selectionModel = jTable1.getSelectionModel();
      selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
      selectionModel.addListSelectionListener(new RowListener(this));
      DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
      Date Sysdate = new Date();
      lblDate.setText(dateFormat.format(Sysdate));
      jXDatePicker1.setFormats(dateFormat);
      Jobs();
  }
  
  public void Jobs() {
      try {
          Connection c = DB.myConnection();
          ResultSet rs = c.createStatement().executeQuery("SELECT * FROM totjobno WHERE ID='todayjob' AND date=('" + lblDate.getText().trim() + "')");
          while (rs.next()) {
              String x = rs.getString("TotJobNo");
              lblCuJobNo.setText(x);
          }
          c.close();
          rs.close();
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  
  private void clearTable() {
  }
  
  private void pendingList2(String getDate) {
      try {
          Connection c = DB.myConnection();
          Statement s = c.createStatement();
          DefaultTableModel tm33 = (DefaultTableModel) jTable1.getModel();
          tm33.setRowCount(0);
          ResultSet r = s.executeQuery("SELECT * FROM newjobsheet WHERE date=('" + getDate + "') ORDER BY sqNumber ");
          while (r.next()) {
              Vector v = new Vector();
              v.addElement(r.getString("sqNumber"));
              v.addElement(r.getString("date"));
              v.addElement(r.getString("JobNumber"));
              v.addElement(r.getString("DecName"));
              tm33.addRow(v);
          }
      } catch (ArrayIndexOutOfBoundsException e) {
          JOptionPane.showMessageDialog(this, "Press OK!!", "Error!", JOptionPane.ERROR_MESSAGE);
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  
  private void btnAllPendingActionPerformed(java.awt.event.ActionEvent evt) {                                              
      jXDatePicker1.setDate(null);
      try {
          DefaultTableModel tm33 = (DefaultTableModel) jTable1.getModel();
          tm33.setRowCount(0);
          Connection c = DB.myConnection();
          Statement s = c.createStatement();
          ResultSet r = s.executeQuery("SELECT * FROM newjobsheet ORDER BY sqNumber ");
          while (r.next()) {
              Vector v2 = new Vector();
              v2.addElement(r.getString("sqNumber"));
              v2.addElement(r.getString("date"));
              v2.addElement(r.getString("JobNumber"));
              v2.addElement(r.getString("DecName"));
              tm33.addRow(v2);
          }
      } catch (ArrayIndexOutOfBoundsException e) {
          JOptionPane.showMessageDialog(this, "Press OK!!", "Error!", JOptionPane.ERROR_MESSAGE);
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  </code></pre>