【发布时间】:2014-04-27 16:46:39
【问题描述】:
在为我的代码运行公共测试时,我收到了 2 个类似行的错误。错误是:
空指针异常错误和它们出现的行是其中包含 getCurrentLocation 和 getName 的行。
assertEquals("最初,Parrade 在 Fun Fire", "Fun Fire", parrade.getCurrentLocation().getName());
parrade.move();
我的构造函数以及getCurrentLocation和getName的完整代码如下:
代码:
public abstract class Ride {
private String name;
private int duration;
private int batchSize;
private ArrayList<Amuser> currentAmusers;
private int ridesToMaintain;
private FunRide location;
public Ride() {
this.name = "Serpent";
this.duration = 5;
this.batchSize = 20;
this.ridesToMaintain = 10;
this.currentAmusers = new ArrayList<Amuser>();
}
public Ride(String name, int duration, int batchSize) {
this.name = name;
this.duration = duration;
this.batchSize = batchSize;
this.ridesToMaintain = 10;
this.currentAmusers = new ArrayList<Amuser>();
}
public FunRide getCurrentLocation() {
return this.location;
}
知道如何解决这个问题吗?
【问题讨论】:
标签: java exception pointers null nullpointerexception