boolean cannot be dereferenced

Hi all any help would be great:

Im getting these errors:

KhanAccount.java:41: boolean cannot be dereferenced

for(int i = 0; i < passwd.length(); i++)

^

KhanAccount.java:42: boolean cannot be dereferenced

if (Character.isDigit(passwd.charAt(i)))

^

KhanAccount.java:45: boolean cannot be dereferenced

if (passwd.length() >= 6 && hasDigit)

^

3 errors

This is the code:

(main method)

import java.text.*;

import javax.swing.*;

public class KhanPassword

{

public static void main (String [] args)

{

KhanAccount oneacct = new KhanAccount ();

inputacct (oneacct);

System.exit(0);

}

public static KhanAccount inputacct (KhanAccount aacct)

{

/* If an invalid password is entered (or the two entries do not match),

the user should be prompted to try again. */

/* Continuously reads a pair of passwords until the two match.*/

do { // Continuously reads the password until it is a valid one.

do {

String password = JOptionPane.showInputDialog("Enter password:\n"

+ "(must be at least six characters long and have at least one digit)");

aacct.setusername(un);

/* display a message indicating whether it is valid or not */

if (!aacct.setPassword(passwd))

JOptionPane.showMessageDialog(null, "Invalid password!");

else {

JOptionPane.showMessageDialog(null, "Valid password!");

break;

}

}

while (true);

/* The password should be prompted for twice */

String reenter = JOptionPane.showInputDialog("Re-enter password:");

/* the entries should match or a message provided to the user. */

if (!passwd.equals(reenter))

JOptionPane.showMessageDialog(null, "Two passwords don't match!");

else

JOptionPane.showMessageDialog(null, "Two passwords match!");

} while (!passwd.equals(reenter));

return aacct;

}

}

(called method)

public class KhanAccount

{

public String username;

public boolean password;

public String reenter;

public boolean passwd;

public static void KhanAccount (){};

public String getusername()

{

return username;

}

public boolean getpassword()

{

return password;

}

public void setusername (String un)

{

username = un;

}

public boolean setPassword()

{

password = passwd;

{

/* check if contains digit*/

boolean hasDigit = false;

for(int i = 0; i < passwd.length(); i++)

if (Character.isDigit(passwd.charAt(i)))

hasDigit = true;

if (passwd.length() >= 6 && hasDigit)

{

password = passwd;

return true;

} else

return false;

}

}

}

[2944 byte] By [sadiaka] at [2007-10-2 4:21:17]
# 1
passwd (and password) are booleanpublic boolean password; public boolean passwd;perhaps they should bepublic String password; public String passwd;
Michael_Dunna at 2007-7-15 23:47:53 > top of Java-index,Java Essentials,New To Java...
# 2
I'd think so. :) @OP: "<primitive> cannot be deferenced" means that you're trying to call a method on a primitive data type. Those don't have any methods, so you can't do it. (Don't confuse primitive boolean and class Boolean, btw.)
CeciNEstPasUnProgrammeura at 2007-7-15 23:47:53 > top of Java-index,Java Essentials,New To Java...
# 3

Btw, isn't better to initiate hasDigit to true and then when

a character is wrong set hasDigit = false and quit loop

with break or so?

And methods called set.. often returns nothing if they return

boolean they are often named with is... or so isPasswd

I've learned basic methods should be divided into three types:

constructors starts with make..

modifiers , set..

predicats , is..

//jF

/* check if contains digit*/

boolean hasDigit = false;

for(int i = 0; i < passwd.length(); i++)

if (Character.isDigit(passwd.charAt(i)))

hasDigit = true;

if (passwd.length() >= 6 && hasDigit)

{

password = passwd;

return true;

} else

return false;

}

}

javaFlowera at 2007-7-15 23:47:53 > top of Java-index,Java Essentials,New To Java...