Помогите мне со списком ссылок sinlgly
Всякий раз, когда я ввожу это, чтобы найти эту ссылку
System.out.println(theEmployeeList.find("Jason").emName + " Found");он всегда показывает мне эту ошибку
& lt;исключение в потоке "main" java. lang.Исключение NullPointerException
at Employee. main (Employee.java:38)>
Извините за беспокойство, но мне действительно нужна ваша помощь, и мой профессор сказал, что она хочет removelast и removeinBetween и добавить в просто студент спасибо за помощь :)
Что я уже пробовал:
import java.util.Scanner; public class Employee { public String emName; public int idNumber; public Employee next; public Employee(String emName, int idNumber) { this.emName = emName; this.idNumber = idNumber; } public void display() { System.out.println(emName + " ID #" + idNumber); } public String toString() { return emName; } public static void main (String [] args) { String search; Scanner sc = new Scanner(System.in); EmployeeList theEmployeeList = new EmployeeList(); theEmployeeList.insertFirstEmployee("Jason " , 1); theEmployeeList.insertFirstEmployee("Percy " , 2); theEmployeeList.insertFirstEmployee("Anabeth " , 3); theEmployeeList.insertFirstEmployee("Grover " , 4); theEmployeeList.display(); System.out.println(theEmployeeList.find("Jason").emName + " Found"); } } class EmployeeList { public Employee firstEmployee; //First link always starts with Null EmployeeList() { firstEmployee = null; } public boolean isEmpty() { return(firstEmployee == null); } //Insert public void insertFirstEmployee(String emName, int idNumber) { Employee newEmployee = new Employee (emName,idNumber); newEmployee.next = firstEmployee; firstEmployee = newEmployee; } public Employee removeFirst() { Employee linkReference = firstEmployee; if(!isEmpty()) { firstEmployee = firstEmployee.next; } else { System.out.println("Empty Link List"); } return linkReference; } public void display() { Employee theEmployee = firstEmployee; while (theEmployee != null) { theEmployee.display(); System.out.println("Next Employee " + theEmployee.next); theEmployee = theEmployee.next; System.out.println(); } } public Employee find(String emName) { Employee theEmployee = firstEmployee; if(!isEmpty()) { while(theEmployee.emName != emName) { if(theEmployee.next == null) { return null; } else { theEmployee = theEmployee.next; } } } else { System.out.println("Empty Link List"); } return theEmployee; } public Employee removeEmployee(String emName) { Employee currentEmployee = firstEmployee; Employee previousEmployee = firstEmployee; while(currentEmployee.emName != emName) { if (currentEmployee.next == null) { return null; } else { previousEmployee = currentEmployee; currentEmployee = currentEmployee.next; } } if (currentEmployee == firstEmployee) { firstEmployee = firstEmployee.next; } else { previousEmployee.next = currentEmployee.next; } return currentEmployee; } }