I'm a new one to use java. My problem may seem naive but I really don't know what to do. Here's the code:
class Employee{
String name;
Employee supervisor;
}
public class EmployeeTest{
public static void main(String[] args){
Employee emp = new Employee();
emp.name = "Xhaka";
emp.supervisor.name = "Origi";
if(emp.supervisor == null){
System.out.println( emp.name + " is the boss and has no supervisor!" );
}
else{
System.out.println("The supervisor of " + emp.name + " is " + emp.supervisor.name);
}
}
}
When I tried to compile it, it shows the problem with this:Exception in thread "main" java.lang.NullPointerException. How can I solve this question?