Newbie Question Coming thru. And to sir JPS I am greatfully thank you and sorry. I've fixed it now.
TO the point. This Code now gives me nullpointerExceptions. I tried putting String to it so It won't return as null but it still won't budge.
The code is giving me three NullPointerExceptions at these lines :startPage();import java.util.Scanner; public class RegistrationofEmployees { public static final String emp[][] = new String[4][4]; public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Registration of Employee"); startPage(); System.out.println("\nProgram Terminated..."); } public static void startPage(){ String employee =""; Scanner input = new Scanner(System.in); System.out.println("Registration of Employee"); System.out.println("============================================"); System.out.println("Enter your Choice: "); System.out.println("============================================"); System.out.println("\t\t[a] Register Employee"); System.out.println("\t\t[b] Time Keeping"); System.out.println(" "); System.out.print("Choose Letter: "); String choice1 = input.next(); if(choice1.length() == 1){ char choice2 = choice1.charAt(0); if (choice2 == 'a' || choice2 == 'A'){ System.out.println("Lalalalala"); }else if(choice2 == 'b' || choice2 == 'B'){ searchEmployee(employee); }else{ System.out.println("============================================"); System.out.println("Invalid Letter"); System.out.println("============================================"); } }else{ System.out.println("Invalid String..!"); } public static String[] searchEmployee(String empNumber){ Scanner input= new Scanner(System.in); System.out.println("Enter Employee Number: "); String empNumber1 = input.next(); String[] employee = new String[4]; if(empNumber1.length() < 5 || empNumber1.length() > 5){ System.out.println("Criteria is invalid."); return null; }else{ for(int x=0;x<emp.length;x++){ if(!emp[x][0].equals("")){ if(emp[x][0].equals(empNumber1)){ employee[0] = emp[x][0]; employee[1] = emp[x][1]; employee[2] = emp[x][2]; employee[3] = emp[x][3]; return employee; } } } } System.out.println("Employee number provided not found!"); return null; } public static void data(String emp[][]){ emp[0][0] = "10000"; emp[0][1] = "John Loudwig"; emp[0][2] = "Alonsagay"; emp[0][3] = "Regular Employee"; emp[1][0] = "10001"; emp[1][1] = "Gienna"; emp[1][2] = "Belonio"; emp[1][3] = "Manager"; emp[2][0] = "10002"; emp[2][1] = "James"; emp[2][2] = "Arcilla"; emp[2][3] = "Supervisor"; }
At the searchemployee(employee);
annnd at this loop under the searchEmployee methodif(choice1.length() == 1){ char choice2 = choice1.charAt(0); if (choice2 == 'a' || choice2 == 'A'){ System.out.println("Lalalalala"); }else if(choice2 == 'b' || choice2 == 'B'){ searchEmployee(employee);
It gives me a nullPointerException at those three lines. I tried making a boolean argument on the startpage(); so that when it returns a null, the system will do something.. but it didnt work. I tried try and catch but I have really no idea what to do with it.if(!emp[x][0].equals("")){
Please help me.