线程AWT-EventQueue-0 java.lang.StackOverflowError中的异常

时间:2014-03-13 06:34:31

标签: java swing

我只是想请求帮助,因为我不知道这个错误是否导致我的程序无法运行。

在我去寻求帮助之前,我做了一些测试和重新调试,以便在我尝试运行程序时找到错误导致的根源。见下面的代码

  public class AcademicPersonnelForm{

 public AcademicPersonnelForm(){
   create();
}

    public static void main(String [] args){


 SwingUtilities.invokeLater(new Runnable(){

public void run(){

new AcademicPersonnelForm();

    }   
 });


}//close main

下面是我创建JFrame的方法“create()”。在这个方法中,我声明了我需要在框架中插入的所有必要组件。(仅在发生错误的地方包含组件)

      public void create(){

      gbc.fill = GridBagConstraints.NONE;
gbc.anchor = GridBagConstraints.LINE_START;
gbc.ipady = 20;
gbc.ipadx = 20;
gbc.gridx = 1;
gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.gridheight = 1;

textEmpNo.addKeyListener(new MyRetrieve());

     textEmpNo.setPreferredSize(new Dimension(80,5));

     textEmpNo.setDocument(new LengthRestrictedDocument(3));
     //add textEmpNo in the main panel              
     gbl.setConstraints(textEmpNo, gbc);
     mainPanel.add(textEmpNo);

            }

我发现上面提到的错误出现在“textEmpNo.addKeyListener(new MyRetrieve());”中,因为当我尝试在此代码中添加注释时,程序运行正常。

“new MyRetrieve()”是我可以生成和检索员工编号的子类。见下面的代码。

      public class MyRetrieve implements KeyListener{

     search_employee_record_db serdb = new search_employee_record_db();
     generate_emp_num_db gendb = new generate_emp_num_db();


    public void keyReleased(KeyEvent e){



    if(e.getKeyCode() == KeyEvent.VK_ENTER){ 

    serdb.EMPNUM = textEmpNo.getText();


     //if(serdb.EmpNo.equals(textEmpNo.getText())){
    if(textEmpNo.getText().equals(serdb.EMPNUM)){


     serdb.retrieved();

    //textEmpNo.setText(serdb.EmpNo);

    textFName.setText(serdb.FName);
    textLName.setText(serdb.LName);
    comboGender.setSelectedItem(serdb.GENDER);
    textAddress.setText(serdb.address);

    comboDay.setSelectedItem(serdb.DAY);
         comboMonth.setSelectedItem(serdb.MONTH);
         comboYear.setSelectedItem(serdb.YEAR);

         textSSS.setText(serdb.sss);
         textReligion.setText(serdb.religion);
    textCitizenship.setText(serdb.citizenship);
         textTIN.setText(serdb.tin);
               textMobileNo.setText(serdb.mobileNumber);
    comboStatus.setSelectedItem(serdb.STATUS);
    comboDHDay.setSelectedItem(serdb.DH_DAY);
    comboDHMonth.setSelectedItem(serdb.DH_MONTH);
    comboDHYear.setSelectedItem(serdb.DH_YEAR);


    update.setEnabled(true);
    }//end of if

          if(serdb.EMPNUM.equalsIgnoreCase("")){


    gendb.generate();

          textEmpNo.setText(gendb.INC);

          comboGender.setSelectedIndex(0);
     comboMonth.setSelectedIndex(0);
     comboDay.setSelectedIndex(0);
     comboYear.setSelectedIndex(0);
     comboDHMonth.setSelectedIndex(0);
     comboDHDay.setSelectedIndex(0);
     comboDHYear.setSelectedIndex(0);
     comboStatus.setSelectedIndex(0);
     textLName.setText("");
     textFName.setText("");
     textAddress.setText("");
     textSSS.setText("");
     textReligion.setText("");
     textTIN.setText("");
     textCitizenship.setText("");
     textMobileNo.setText("");


   }//end of if


  else if(!textEmpNo.getText().equals(serdb.EmpNo)){

     comboGender.setSelectedIndex(0);
     comboMonth.setSelectedIndex(0);
     comboDay.setSelectedIndex(0);
     comboYear.setSelectedIndex(0);
     comboDHMonth.setSelectedIndex(0);
     comboDHDay.setSelectedIndex(0);
     comboDHYear.setSelectedIndex(0);
     comboStatus.setSelectedIndex(0);
     textLName.setText("");
     textFName.setText("");
     textAddress.setText("");
     textSSS.setText("");
     textReligion.setText("");
     textTIN.setText("");
     textCitizenship.setText("");
     textMobileNo.setText("");


  JOptionPane.showMessageDialog(null,"employee number does not exist");     


   textEmpNo.selectAll();   


    }//end of else if

    }//end of outer if   

     } //end method

    public void keyTyped(KeyEvent e) {
            // TODO: Do something for the keyTyped event
        }

        public void keyPressed(KeyEvent e) {
            // TODO: Do something for the keyPressed event
        }


   }//close inner class

有人可以向我解释为什么上面提到的错误发生了。感谢

0 个答案:

没有答案