事件分派期间发生异常:java.lang.ArrayIndexOutOfBoundsException:0> = 0

时间:2013-07-04 08:59:06

标签: java swing

有时会遇到此异常。我真的不知道哪里有问题,如果我在下面的代码中使用线程我得到错误,否则没有。如果我连续点击则会出现问题 事件调度期间发生异常:

 private Thread progress_thread;
boolean threadStatus;

private void useThread(final String opt) {
    try {

        Runnable runnable = new Runnable() {

            public void run() {
                if (opt != null && opt.equalsIgnoreCase("searchbyMid")) {                       
                    callGlasspane();
                      constructDynamic();
                    closeGlasspane();
                }else if(opt != null && opt.equalsIgnoreCase("searchbyQrybased")){
                    callGlasspane();
                      createGUI();
                    closeGlasspane();
                } 
            }
        };
     worker = new SwingWorker() {
            public Object construct() {
                return "";
            }
            public void finished() {
                thread1();
            }
        };
        worker.start();
        Thread thread = new Thread(runnable);
        thread.start();

    } catch (Exception e) {
        System.out.println("Exception raised in useThread() :" + e);
        e.printStackTrace();
    }
}
Thread prg_thread;

private void thread1() {
    Runnable run_prg = new Runnable() {
        public void run() {
            prgRunning();
        }
    };
    progress_thread = new Thread(run_prg);
    progress_thread.start(); 
}
 private void prgRunning() {
    try {
        while (true) {
            Runnable doSetProgressBarValue = new Runnable() {

                public void run() {
                    if (threadStatus) {
                        progress_thread.stop();
                    }

                }
            };
            SwingUtilities.invokeLater(doSetProgressBarValue);
            Thread.sleep(10);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
} 

private void callGlasspane(){
    try{
          JRootPane rootPane = SwingUtilities.getRootPane(jPanel3);
        rootPane.setGlassPane(glass);
        glass.activateMulti("");
    }catch(Exception e) {
        System.out.println("Exception in callglass" +e);
        closeGlasspane();
        e.printStackTrace();
    }

}
private void closeGlasspane(){
    try{
        glass.deactivate();
        glass.close();

    }catch(Exception e) {
        System.out.println("Exception in closeglass" +e);
        e.printStackTrace();
    }

}
private void setGridValues(Vector myVec) {
    try {            
        java.util.Enumeration e=myVec.elements();
        int r=0;   
        grid1.setRowCount(0);
        System.out.println("grid length:"+grid.getRowCount());
        System.out.println("grid1 length:"+grid1.getRowCount());
        while(e.hasMoreElements()) {
            grid.setValueAt(new Boolean(false),r, 0);
            grid1.setValueAt(new Boolean(false),r, 0);
            for(int col=0;col<scolheader.length;col++) {
                String val=(String)e.nextElement();

      if(val!=null && !val.trim().equalsIgnoreCase("null") &&  val.trim().length()>0) {
                    grid.setValueAt(val,r,col+1);
                    grid1.setValueAt(val,r,col+1);                       
                }
                else {
                    grid.setValueAt("",r,col+1);
                    grid1.setValueAt("",r,col+1);                       

                }
            }
            r++;

        }

    }catch(ArrayIndexOutOfBoundsException e) {

        e.printStackTrace();
    }
    catch(Exception e) {
        System.out.println("Exception raised in setGridValues(): "+e);
        e.printStackTrace();
    }
}

0 个答案:

没有答案