I have to create a simple login program using a public class and the main driver console.
Here's my code:
Main
import java.util.Scanner;
public class main
{
public static void main(String[] args)
{
Scanner input = new Scanner (System.in);
String username;
String password;
System.out.println("Welcome to your Social network site!");
System.out.println("\nEnter your username and password to login to your account.");
System.out.println("Username: ");
username = input.nextLine();
System.out.println("Password: ");
password = input.nextLine();
UserAccount login = new UserAccount(username, password);
if(login.checkPassword())
System.out.println("You are logged in!");
else
System.out.println("The username and password you entered are incorrect.");
}
}
User Class
public class UserAccount
{
private String username;
private String password;
private String[][] accounts = {{"anthony", "supernova"},{"steve", "java1"}};
public UserAccount(String username, String password)
{
String user = username;
String pass = password;
boolean active;
}
public boolean checkPassword()
{
if((username.equals(accounts[0][0])) && (password.equals(accounts[0][1])))
return true;
else
return false;
}
public void deactivateAccount()
{
boolean active = false;
}
}
The problem is I keep getting this error after I input the correct info: Exception in thread "main" java.lang.NullPointerException at UserAccount.checkPassword(UserAccount.java:19)at main.main(main.java:25)