Java JPasswordField length跳过检查
我一直在读:但我有一个问题。我得到了一个简单的方法来检查我的Java JPasswordField length跳过检查,java,swing,jpasswordfield,Java,Swing,Jpasswordfield,我一直在读:但我有一个问题。我得到了一个简单的方法来检查我的JTextFields和我的JPasswordFields是否为空 所以我有一个: private boolean addCustomerCheckValidInfo() { for(JPasswordField pf : newCustomerPasswordFields) { if (pf.getPassword().length == 0); { System
JTextField
s和我的JPasswordField
s是否为空
所以我有一个:
private boolean addCustomerCheckValidInfo()
{
for(JPasswordField pf : newCustomerPasswordFields)
{
if (pf.getPassword().length == 0);
{
System.out.println("Password length " + pf.getPassword().length);
return false;
}
}
return true;
}
该函数返回false并在控制台中写入:
Password length 3
正如我在《oracle指南》中所读到的,passfield.getPassword().length应该返回长度(在system.print.out中也是如此),但是当它大于0时,如果它等于0,为什么会失败呢
if (pf.getPassword().length == 0);
你打错了。您在if语句的末尾添加了“;”。所以您确实创建了一个空的if语句。扔掉“;”天哪。。非常感谢,我完全错过了那一个>。