Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

boolean cannot be dereferenced

807597Nov 4 2005 — edited Nov 5 2005
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;
}
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 3 2005
Added on Nov 4 2005
3 comments
2,903 views