I have three classes: Crew, Plane and Driver. Crew class is accessed only through the Plane class and Plane class is actually used through the Driver class. The program compiles but upon execution, throws the error:
Exception in thread "main" java.lang.NullPointerException
at Plane.addCrew(Plane.java:180)
at Carrier.addCrew(Carrier.java:493)
at Carrier.process(Carrier.java:179)
at Carrier.run(Carrier.java:144)
at Carrier.main(Carrier.java:54)
Below is the snippet from the Plane class specific to the problem:
public void addCrew(String name, String role, int id, int missions)
{
if(currentCrew < maxCrew)
{
Crew crew = new Crew(name, role, id, missions);
crewArray[currentCrew] = crew; //This is Plane.addCrew(Plane.java:180)
++currentCrew;
}
else
{
System.out.println("Crew is full");
}
}