setter中的值来自JTextFeild。我尝试了不同的方法,但它不起作用。我想打印出我的自定义错误信息。它不适用于double,String变量在堆栈跟踪中显示错误消息。验证setter方法中的输入是double还是String
这是String方法。
public void setInventoryname(String inventoryname) throws Exception {
if(inventoryname.isEmpty()){
throw new Exception ("Medicine name cannot be empty");
}
else{
this.inventoryname = inventoryname;
}
}
字符串方法的结果。
java.lang.Exception: Medicine name cannot be empty
这就是双方法
public void setInventorydesc(double inventorydesc) throws Exception {
if(!Double.toString(inventorydesc).isEmpty()){
throw new Exception("Set a number in Inventory qunatity");
}
else
{
this.inventoryqty = inventorydesc;
}
}
的双
java.lang.NumberFormatException: For input string: "dfasdf"
我希望收到相同的结果字符串双的结果。
我检查出来了。没有得到一件事。是否有任何简单的解决方案,以适应if条件或什么。 – Ace