I am trying to search for a customer by using these two methods below but i am getting this error while doing so The customer with id 20131111 is not in the list and I just want it to return null to the console
public Customer search(int id){
int year = idToYear(id);
SLLC listOfCustomers = (SLLC) tree.search(year);
Customer x = listOfCustomers.getCust(id);
//if (listOfCustomers == null) return null;
//for (int i=1; i<listOfCustomers.size()+1; i++){
// Customer searchedCustomer = listOfCustomers.get(i);
//if (searchedCustomer.getId() == id){
//return searchedCustomer;
//}
//}
return x;
}
public Customer getCust(int id) {
Node temp = head;
if(temp.equals(null) ) {
return null;
}
else
{
while(temp != null) {
if(temp.data.getId() == id) {
break;
}
else
{
temp = temp.next;
}
}
return temp.data;
}
}
This is in the test class at line 71 I know error occurrig because the cutomer with this ID is not in the list but how to I make this just return null
System.out.println(gym.search(20131111));
the error
Exception in thread "main" java.lang.NullPointerException
at GYM.search(GYM.java:30)
at TestClass.main(TestClass.java:71)