java如果条件不能正常工作
我正在对combobox做一个简单的检查,如果combobox的值被选中或未选中,但是当第二个条件为true时,则不显示通知,当第一个条件为true时,则显示通知。下面是代码java如果条件不能正常工作,java,if-statement,Java,If Statement,我正在对combobox做一个简单的检查,如果combobox的值被选中或未选中,但是当第二个条件为true时,则不显示通知,当第一个条件为true时,则显示通知。下面是代码 if(cboContactType.getValue() == null || cboCountry.getValue() == null){ Notification.show("Contact type and country can't be empty"); } else if(cboContactType.g
if(cboContactType.getValue() == null || cboCountry.getValue() == null){
Notification.show("Contact type and country can't be empty");
} else if(cboContactType.getValue().equals("Email")) {
if(txtEmail.getValue() == null) {
Notification.show("Email can'nt be empty");
}
}
告诉我哪里错了。谢谢:)
或者只是调试(或者简单地将System.out.println(“值为:+cboContactType.getValue()”)添加到代码中,您将看到真正的值错误很可能是您的代码没有使用您认为的值。请记住:“与nullDebug不同,您将了解测试时使用的.post值。我建议使用类似StringUtils.isEmpty()的内容与从org.apache.commons.lang.StringUtils或等效项执行空检查不同,这是一个非常简单的if-else块。只需调试以查看其工作方式。如果未显示某些通知,则会跳过if或else主体,因为不满足条件
if(cboContactType.getValue() == null || cboContactType.getValue().equals("") || cboCountry.getValue() == null || cboCountry.getValue().equals("")){