我收到一个错误,我不知道它来自哪里?这是我认为问题所在:
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;
}
这对应于一个动作方法:
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");
}
}
请帮我弄清楚错误可能是由什么引起的???