日期:2014-05-20  浏览次数:20647 次

一小段程序,请高手们近来看看是哪里的问题?很着急啊!!!
public   void   actionPerformed(ActionEvent   e){
String   s=e.getActionCommand();
if(s.equals( "确定 ")){
if(this.jtfImpP.getText()== " "||this.jtfImpQ.getText()== " "||this.jtfIniP.getText()== " "||this.jtfIniQ.getText()== " "||this.jtfResP.getText()== " "||this.jtfResQ.getText()== " ")
{
JOptionPane.showConfirmDialog(jf, "dfdsfdf ", "message ",JOptionPane.DEFAULT_OPTION,JOptionPane.QUESTION_MESSAGE);
}
else
{
javaConnectToSql   jcts=new   javaConnectToSql();//实例化javaConnectToSql
                jcts.Conn( "com.microsoft.jdbc.sqlserver.SQLServerDriver ", "jdbc:microsoft:sqlserver://localhost:1433;databaseName=biyesheji ", "sa ", " ");
                jcts.UpdateSql( "insert   into   parameterSet   values   ( ' ', ' "+Float.parseFloat(this.jtfIniP.getText())+ " ', ' "+Float.parseFloat(this.jtfIniQ.getText())+ " ', ' "+Float.parseFloat(this.jtfResP.getText())+ " ', ' "+Float.parseFloat(this.jtfResQ.getText())+ " ', ' "+Float.parseFloat(this.jtfImpP.getText())+ " ', ' "+Float.parseFloat(this.jtfImpQ.getText())+ " ') ");
}
}
else   if(s.equals( "取消 ")){
jf.dispose();
}
else   if(s.equals( "清除 ")){
this.jtfImpP.setText( " ");
this.jtfImpQ.setText( " ");
this.jtfIniP.setText( " ");
this.jtfIniQ.setText( " ");
this.jtfResP.setText( " ");
this.jtfResQ.setText( " ");
                }
}
这段程序的本意是想,在点击“确定”按钮后,判断这6个JTextField是否为空。如果任意一个为空,就弹出提示框,如果都不为空,则插入到数据库中的表里。

可问题是:如果有空字段,在点击“确定”按钮后,不弹出提示框,而是出现以下错误:
Exception   occurred   during   event   dispatching:
java.lang.NumberFormatExcetion:empty   String

不知道哪里错了,请教各位!!!

------解决方案--------------------
判断条件改成
if(jtfImpP.getText().length()==0||jtfImpQ.getText().length()==0)试下