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不知道哪里错了,请教各位!!!
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不知道哪里错了,请教各位!!!
(这个是楼主的毕设吧?呵呵)
字符串转换成数字产生了错误可以原因是你的文本框中含有 “空格”, 而你后面又含有Float.parseFloat这些方法,
如果是判断空格, this.jtfResQ.getText().trim()这样既可,但是你并没有判断文本框中的内容是否是数字,同样会出现其他问题。希望你判断周密些
if(jtfImpP.getText().length()==0||jtfImpQ.getText().length()==0)试下
jtfImpP.getText().equals("");注意不是==号
不过专业测试用长度最快
{你。这段。并没有判断空格 “”是代表(空字符),空格是字符的一种。。