質問

I have been reading this: http://docs.oracle.com/javase/tutorial/uiswing/components/passwordfield.html but I have a problem. I got a simple method which checks if my JTextFields and my JPasswordFields are empty or not

So I have this one:

private boolean addCustomerCheckValidInfo()
{
    for(JPasswordField pf : newCustomerPasswordFields)
    {
        if (pf.getPassword().length == 0);
        {
            System.out.println("Password length " + pf.getPassword().length);
            return false;
        }
    }

    return true;
}

The same returns false and writes in the console:

Password length 3

As I have read on the oracle guide, passfield.getPassword().length should return the length (as it does in the system.print.out), but why does it fail at if it's equals to 0 when it's > 0?

役に立ちましたか?

解決

if (pf.getPassword().length == 0);

You have a typo. You added a ";" at the end of the if statement. So you really created an empty if statement. Get rid of the ";".

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top