我想输入一个价格并将其写入到一个文本文件中,但它给出了一个"double cannot be dereferenced“错误。
这是我的代码片段。
String id = "P" + ProductID.getText();
String name = ProductName.getText();
String brand = ProductBrand.getText();
String model = ProductModel.getText();
String type = ProductType.getText();
double price = Double.parseDouble(ProductPrice.getText());
if (id.isEmpty() || name.isEmpty() || brand.isEmpty() || model.isEmpty() || type.isEmpty() || price.isEmpty())
{
JOptionPane.showMessageDialog(null, "Please Fill In Everything!", "Error", JOptionPane.ERROR_MESSAGE);
}发布于 2018-11-16 00:19:41
price是double的原始类型-它不是对象。所以你不能在它上面执行像.xxx()这样的操作。
相反,您可以检查以下示例
if(price != 0.0)发布于 2018-11-16 00:24:57
试试看:
String tmp = ProductPrice.getText();
if(tmp.isEmpty()) // error
else{
double price = Double.parseDouble(tmp);
// do something
}https://stackoverflow.com/questions/53323657
复制相似问题