我正在尝试Parcel
在同一位置添加不同的对象。我的代码如下所示,其中Rock
extends Parcel
:
Point origin = null;
Rock rock = null;
for (int i = 0; i < ROCKS; i++) {
if (i % 10 == 0) {
origin = model.getRandomUnoccupiedPosition(sim.getRandomGenerator());
rock = new Rock(origin, destination);
sim.register(rock);
} else {
Rock r = new Rock(origin, destination);
model.addObjectAtSamePosition(r, rock);
}
}
但经过几次迭代后,我在尝试Rock
使用 a时收到此错误Vehicle
:
Exception in thread "Thread-1" java.lang.IllegalArgumentException: Parcel must be registered and must be either ANNOUNCED or AVAILABE, it is: null. Parcel: [Parcel-103f852].
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:146)
at com.github.rinde.rinsim.core.model.pdp.DefaultPDPModel.pickup(DefaultPDPModel.java:175)
at me.alexrs.mas.roveragent.RoverAgent.tickImpl(RoverAgent.java:105)
at com.github.rinde.rinsim.core.model.pdp.Vehicle.tick(Vehicle.java:55)
at com.github.rinde.rinsim.core.model.time.TimeModel.tickImpl(TimeModel.java:139)
at com.github.rinde.rinsim.core.model.time.SimulatedTimeModel.doStart(SimulatedTimeModel.java:32)
at com.github.rinde.rinsim.core.model.time.TimeModel.start(TimeModel.java:94)
at com.github.rinde.rinsim.ui.SimulationViewer$5.run(SimulationViewer.java:399)
唯一Rock
注册的是在 中注册的那个Simulator
,但是如果我尝试注册多个Rock
,我会得到一个异常,说两个对象不能在同一个位置。