I am new to Java and I am doing a project for my computer science class. I have to add details to a multi-dimensional array. Here is my code
public class Login {
public static String[][] all_users = new String[50][13];
public static void main(String[] args){ //throws FileNotFoundException {
welcome();
userSearch user_info = new userSearch();
user_info.fileSearch(all_users);
Scanner userIn = new Scanner(System.in);
String input = userIn.next();
switch (input) {
case "1":
user_info.viewUserList(all_users);
break;
case "2":
AddUser.addDetails();
break;
case "3":
System.out.println("please enter administrator password to modify or delete contents: ");
Pass.getPassword();
break;
}
}
private static void welcome() {
System.out.println("Welcome to the user information profiler. \n here are your options, please enter one of the numbers: ");
System.out.println("1) view a list of all current users. /n 2) Add user details to the list."
+ "/n 3) if you know the administrator password and wish to modify or delete user details.");
System.out.println("Enter a choice now: ");
}
}
and the Add user class
public class AddUser extends Login {
public static void addDetails(){
System.out.println("Please add details for a new user: ");
for (int i = 0; i < all_users.length; i++){
if (all_users [i][0] == null){
for (int j = 0; j < 13; j++){
Scanner scan = new Scanner(System.in);
switch(all_users[i][j]) {
case "1":
System.out.println("input first name: ");
all_users[i][0] = scan.next();
break;
case "2":
System.out.println("input last name: ");
all_users[i][1] = scan.next();
break;
case "3":
System.out.println("input phone number(xxxyyyzzzz): ");
all_users[i][2] = scan.next();
break;
case "4":
System.out.println("input email address: ");
all_users[i][3] = scan.next();
break;
case "5":
System.out.println("input Apartment Number: ");
all_users[i][4] = scan.next();
break;
case "6":
System.out.println("input Street Adress: ");
all_users[i][5] = scan.next();
break;
case "7":
System.out.println("input City: ");
all_users[i][6] = scan.next();
break;
case "8":
System.out.println("input State (ex. NJ): ");
all_users[i][7] = scan.next();
break;
case "9":
System.out.println("input Zip Code: ");
all_users[i][8] = scan.next();
break;
case "10":
System.out.println("input Vehicle Type(ex. luxury, sport): ");
all_users[i][9] = scan.next();
break;
case "11":
System.out.println("input Vehicle Model(ex. Toyota, Nissan: ");
all_users[i][10] = scan.next();
break;
case "12":
System.out.println("input Vehicle Color: ");
all_users[i][11] = scan.next();
break;
case "13":
System.out.println("input License Plate: ");
all_users[i][12] = scan.next();
break;
}
}
}
}
}
}
I get a NullPointerException
switch(all_users[i][j]) {
and on
AddUser.addDetails();
Why is this happening, and how can i fix it?