Im getting an error and i have no idea where it is coming from? Heres where i think the problem lies:

public boolean verifyLogin(String username, String password)
{    
    //method to check if the Login details math those in the text file
    //Parameters are the username and password used to verify login
    //returns a boolean to indicate whether the login is legitimate
    boolean flag = false;
    try 
    {
        Scanner sc = new Scanner(new FileReader("src\\Users.txt"));
        while (sc.hasNext()) 
        {                     
            Scanner b = new Scanner(sc.nextLine()).useDelimiter("#");
            String uName = sc.next();
            String pWord = sc.next();

            if (username.equalsIgnoreCase(uName) & password.equalsIgnoreCase(pWord)) 
            {
                JOptionPane.showMessageDialog(null, "Login Successfull. /n Welcome");     
                flag = true;
            }
            else
            {
                JOptionPane.showMessageDialog(null, "Login Unsuccessfull. /n Please re-enter your details");
                flag = false;
            }               

        }
    } 
    catch (FileNotFoundException ex)
    {
        System.out.println("File was not found " + ex.getMessage() );
    }
    return flag;

}

This corresponds with an action method:

private void LoginButtonActionPerformed(java.awt.event.ActionEvent evt) 
{                                            
    GuiClass gC = new GuiClass();
    Welcome w = new Welcome();
    boolean f = gC.verifyLogin(UsernameField.getText(), PasswordField.getText());

    if (f = true) 
    {
        this.setVisible(false);
        w.setVisible(true);      
    }
    else
    {
        System.out.println("It works");
    }
} 

Please help me figure out what the error could be caused by???

1

There are 1 best solutions below

1
On

You might want to change your = which assigns true to f by a comparaison operator ==

if (f == true) 
{
  this.setVisible(false);
  w.setVisible(true);      
}
else
{
  System.out.println("It works");
}