简体   繁体   English

线程“ AWT-EventQueue-0”中的异常java.lang.NumberFormatException:空

[英]Exception in thread “AWT-EventQueue-0” java.lang.NumberFormatException: empty

anyone can help me? 有人可以帮助我吗? I got this exception in Netbeans 我在Netbeans中遇到了这个异常

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: 
empty 
String
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1842)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:538)

and this is part of my code that probably makes the exception : 这是我的代码的一部分,可能会导致异常:

   private void pizzaMouseClicked(java.awt.event.MouseEvent evt) {                                        
   double cMeal = Double.parseDouble(costmeal.getText());
   double qPizza = Double.parseDouble(qtypizza.getText());
   double cPizaa = 6000;


        if(pizza.isSelected())
        {
        i[0] = (qPizza * cPizaa) + cMeal;
        String pMeal = String.format("%.2f", i[0]);
        costmeal.setText(pMeal); 
        }
}   

Can anyone tell me how to fix it? 谁能告诉我如何解决? Thank you 谢谢

您必须检查costmeal.getText()和qtypizza.getText()均包含有效数字,根据快照代码和堆栈跟踪,似乎其中之一为空。

NumberFormatException is an Exception that might be thrown when you try to convert a String into a number(int, double, float etc..). NumberFormatException是当您尝试将String转换为数字(int,double,float等)时可能引发的异常。 You have to handle the exception either by putting the code inside try catch or add the exception to the method signature. 您必须通过将代码放在try catch中或将异常添加到方法签名中来处理异常。

private void pizzaMouseClicked(java.awt.event.MouseEvent evt) throws NumberFormatException {                                        
   double cMeal = Double.parseDouble(costmeal.getText());
   double qPizza = Double.parseDouble(qtypizza.getText());
   double cPizaa = 6000;
   if(pizza.isSelected())
   {
       i[0] = (qPizza * cPizaa) + cMeal;
       String pMeal = String.format("%.2f", i[0]);
       costmeal.setText(pMeal); 
    }
}   

Or 要么

private void  pizzaMouseClicked(java.awt.event.MouseEvent evt) {       
    try{                                 
        double cMeal = Double.parseDouble(costmeal.getText());
        double qPizza = Double.parseDouble(qtypizza.getText());
        double cPizaa = 6000;


        if(pizza.isSelected())
        {
            i[0] = (qPizza * cPizaa) + cMeal;
            String pMeal = String.format("%.2f", i[0]);
           costmeal.setText(pMeal); 
    }
    }
    catch(NumberFormatException e){
        e.printStackTrace();
    }
}   

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 线程“ AWT-EventQueue-0”中的异常java.lang.NumberFormatException - Exception in thread “AWT-EventQueue-0” java.lang.NumberFormatException 错误“线程“AWT-EventQueue-0”中的异常java.lang.NumberFormatException” - Error "Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException" 线程“ AWT-EventQueue-0”中的异常java.lang.NumberFormatException:空字符串:Java中的错误 - Exception in thread “AWT-EventQueue-0” java.lang.NumberFormatException: empty String: Error in Java 线程“ AWT-EventQueue-0”中的异常java.lang.NumberFormatException:空字符串 - Exception in thread “AWT-EventQueue-0” java.lang.NumberFormatException: empty String 线程“AWT-EventQueue-0”中的异常 java.lang.NumberFormatException 但字符串不为空 - Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException but string is not empty 线程“ AWT-EventQueue-0”中的异常java.lang.NumberFormatException:空字符串。 - Exception in thread “AWT-EventQueue-0” java.lang.NumberFormatException: empty String. 线程“ AWT-EventQueue-0”中的异常java.lang.NumberFormatException:空字符串……但如何解决 - Exception in thread “AWT-EventQueue-0” java.lang.NumberFormatException: empty String… but how to solve 线程“ AWT-EventQueue-0”中的异常java.lang.NumberFormatException:空字符串OS内核模拟 - Exception in thread “AWT-EventQueue-0” java.lang.NumberFormatException: empty String OS Kernel Simulation java parseint-线程“ AWT-EventQueue-0”中的异常java.lang.NumberFormatException:对于输入字符串:“” - java parseint - Exception in thread “AWT-EventQueue-0” java.lang.NumberFormatException: For input string: “” 线程“ AWT-EventQueue-0”中的异常java.lang.NumberFormatException:对于输入字符串:“ java中的78错误 - Exception in thread “AWT-EventQueue-0” java.lang.NumberFormatException: For input string: "78 error in java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM