我对 Java 编程非常陌生,我正在学习基于 Java 的课程。我目前正在做这个基于布尔值和 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);
...
}