我有三个班:船员,飞机和司机。 Crew类只能通过Plane类访问,而Plane类实际上是通过Driver类使用的。程序编译但在执行时抛出错误:
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)
以下是特定于问题的Plane类的片段:
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");
}
}