获取随机" AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException

时间:2016-01-05 16:38:13

标签: java swing indexoutofboundsexception

我随机得到一个:

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: x >= y 

(其中x和y是每次发生异常时的变化值,例如第一次x为7且y为7,下一次x为4且y为2)。以下是我认为错误发生的方法。我说相信是因为堆栈跟踪没有显示对此方法中特定代码行的任何引用。但是,此方法是在关联类中使用向量的唯一区域。

    private void displayResults(ResultSet rset){

      Vector<Vector<String>> resultRows = new Vector<Vector<String>>();
      Vector<String> resultRow = null;
      int resultCount = 0;

      try{
         resultRows.clear();
         if (rset != null){
          while (rset.next()){
              resultRow = new Vector<String>();
              resultRow.add(rset.getString(1));
              resultRow.add(rset.getString(2));
              resultRow.add(rset.getString(3));
              resultRow.add(rset.getString(4));
              resultRow.add(rset.getString(5));
              resultRow.add(rset.getString(6));
              resultRow.add(rset.getString(7));
              resultRow.add(rset.getString(8));
              resultRow.add(rset.getString(9));

              resultRows.add(resultRow);
              resultCount++;                
          }

          try{
             vax.swing.SwingUtilities.invokeAndWait(new Runnable(){
               public void run(){
                  resultsTable.setModel(new DefaultTableModel(resultRows, colHdrs));
                  resultsTable.setForeground(Color.BLUE);
                  resultsTable.setPreferredScrollableViewportSize(new Dimension(950, 480));
                  resultsTable.getColumnModel().getColumn(0).setMaxWidth(100);
                  resultsTable.getColumnModel().getColumn(1).setMaxWidth(50);
                  resultsTable.getColumnModel().getColumn(2).setMaxWidth(50);
                  resultsTable.getColumnModel().getColumn(3).setMaxWidth(50);
                  resultsTable.getColumnModel().getColumn(4).setMaxWidth(50);
                  resultsTable.getColumnModel().getColumn(5).setMaxWidth(50);
                  resultsTable.getColumnModel().getColumn(6).setMaxWidth(50);
                  resultsTable.getColumnModel().getColumn(7).setMaxWidth(100);
                  resultsTable.getColumnModel().getColumn(8).setMaxWidth(100);
               }
             )};
          }
          catch (InterruptedException e){

          }
          catch (InvocationTargetException e){

          }

          .... Code to display results ...

         }
      }
      catch (Exception e){
        Sysyem.err.println("Exception encountered processing a result");
        e.printStackTrace();
      }

    }

提供堆栈跟踪的第一部分:

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 4>= 2
    at java.util.Vector.elementAt(Vector.java:447)
    at javax.swing.table.DefaultTableColumnModel.getColumn(DefaultTableColumnModel.java:294)

注意:

  1. resultsTable是一个JTable
  2. 如上所述,每次执行此方法时都不会发生异常
  3. 异常似乎不会阻止所有结果正确显示 基于目视检查

0 个答案:

没有答案