gpt4 book ai didi

java - 线程中的异常 "AWT-EventQueue-0"java.lang.NumberFormatException : For input string: "1 "

转载 作者:行者123 更新时间:2023-12-02 01:41:46 32 4
gpt4 key购买 nike

我对 Java 编程非常陌生,我正在学习基于 Java 的类(class)。我目前正在做这个基于 boolean 值和RadioButtons 的咖啡项目。我相信我几乎已经完成了,除了我在控制台上收到此错误消息。如果有任何其他错误,请告诉我,以便我修复!

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "1 "
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
<小时/>
    public void purchase()
{
//local variables
String quantityString, buttonString, nameString, coffeeType;

float subTotalFloat, priceFloat, taxFloat, grandTotalFloat;
int quantityInteger;

//Format the values to currency format
DecimalFormat valueDecimalFormat = new DecimalFormat("$#0.00");

//retrieve the input from the user
nameString = nameTextField.getText();
quantityString = quantityTextField.getText();
buttonString = coffeeType ();

//change data types
quantityInteger = Integer.parseInt(quantityString);
...
}

最佳答案

将您的 Integer.parseInt(quantityString); 更改为 Integer.parseInt(quantityString.trim());,您的代码将正常工作!

关于java - 线程中的异常 "AWT-EventQueue-0"java.lang.NumberFormatException : For input string: "1 ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23124582/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com