首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何将双精度值写入JTextField?

如何将双精度值写入JTextField?
EN

Stack Overflow用户
提问于 2018-11-16 00:17:07
回答 2查看 129关注 0票数 1

我想输入一个价格并将其写入到一个文本文件中,但它给出了一个"double cannot be dereferenced“错误。

这是我的代码片段。

代码语言:javascript
运行
复制
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);
}
EN

回答 2

Stack Overflow用户

发布于 2018-11-16 00:19:41

pricedouble的原始类型-它不是对象。所以你不能在它上面执行像.xxx()这样的操作。

相反,您可以检查以下示例

代码语言:javascript
运行
复制
if(price != 0.0)
票数 2
EN

Stack Overflow用户

发布于 2018-11-16 00:24:57

试试看:

代码语言:javascript
运行
复制
String tmp = ProductPrice.getText();
if(tmp.isEmpty()) // error
else{
double price = Double.parseDouble(tmp);
// do something
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53323657

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档