why am i getting this error: error: cannot find symbol if((username==user_name)
ID: 3740664 • Letter: W
Question
why am i getting this error:
error: cannot find symbol
if((username==user_name) && (password == hashed_password))
^
symbol: variable password
location: class cooperbooks
2 errors
cooperbooks.java:119: error: cannot find symbol
if((username==user_name) && (password == hashed_password))
^
symbol: variable username
location: class cooperbooks
cooperbooks.java:119: error: cannot find symbol
if((username==user_name) && (password == hashed_password))
^
symbol: variable password
location: class cooperbooks
here is my code
while(result.next())
{
user_name = result.getString(1);
if (result.wasNull())
{
user_name = null;
} //if
hashed_password = result.getString(2);
if (result.wasNull())
{
hashed_password= null;
} // if
// Enter your user name and password
String username = new String();
String password= new String();
System.out.println("Enter Username");
username=input.nextLine();
System.out.println ("Enter password");
password= input.nextLine();
// if statement to check if the user name and password is valid
}
if((username==user_name) && (password == hashed_password))
{
System.out.println("Log is invalid");
// System.out.println(" do want to be a member, Yes or No ?");
// decision=input.nextLine();
}
else
{
System.out.println("Welcome Member");
//System.out.println("Select option");
//displayMenu();
} // while
}
Explanation / Answer
It is because you might not have declared the user_name variable. You just started using it, but you didn't declare it as String.
So, please check if this works
while(result.next())
{
String user_name = result.getString(1);
if (result.wasNull())
{
user_name = null;
} //if
String hashed_password = result.getString(2);
if (result.wasNull())
{
hashed_password= null;
} // if
// Enter your user name and password
String username = new String();
String password= new String();
System.out.println("Enter Username");
username=input.nextLine();
System.out.println ("Enter password");
password= input.nextLine();
// if statement to check if the user name and password is valid
}
if((username==user_name) && (password == hashed_password))
{
System.out.println("Log is invalid");
// System.out.println(" do want to be a member, Yes or No ?");
// decision=input.nextLine();
}
else
{
System.out.println("Welcome Member");
//System.out.println("Select option");
//displayMenu();
} // while
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.