이것은 코드이며 문자를 입력 할 때 대신 .matches 행을 표시하지 않습니다. 오류가 발생하지만 parseFloat rec1을 제거하고 else를 제거하면 rec1 < total) 다음에 .matches 행이 표시됩니다.이 작업을 수행하는 방법을 미리 알려주십시오.java.lang.NumberFormatException 입력 문자열 값이 문자
CashType c = new CashType(); c.setVisible (true); 당신이 jTextField1에 "asdasd"를 입력하는 것처럼
c.jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
String receive = c.jTextField1.getText();
float total = total("sellno"+SellNoCount.getText());
float rec1 = Float.parseFloat(receive); //this is line 1525
if(!receive.matches("[0-9]+")){
JOptionPane.showMessageDialog(null,"Enter a Valid Amount");
c.jTextField1.setText("");
}
else if(receive.equalsIgnoreCase("")){
JOptionPane.showMessageDialog(null,"Enter Amount");
}
else if(rec1 < total){
JOptionPane.showMessageDialog(null,"Insufficient Amount");
}
// ERROR
오류 메시지에서Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "asdasd"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
at sun.misc.FloatingDecimal.parseFloat(FloatingDecimal.java:122)
at java.lang.Float.parseFloat(Float.java:451)
at projectfinal.SellPage$32.actionPerformed(SellPage.java:1525)
입니다. – shmosel
그리고 일치하는지 확인하기 전에 비어 있는지 확인해야합니다. – shmosel
'if (! receive.matches ("[0-9] +"))'값을 구문 분석하기 전에이 조건을 확인하십시오. –