我正在使用步行图书馆。此时,模型正在创建许多代表货架模块的矩形墙,行人进入并移动到一个点,然后退出。
墙壁是在启动时根据 x、y 坐标和尺寸的数据库表创建的。
Level level = new Level(this, "mylevel", SHAPE_DRAW_2D3D, 0);
List<Tuple> rows = selectFrom(sheet1)
.list();
for (Tuple row : rows) {
int xPos = row.get(sheet1.graphics_pivot_point_x);
int yPos = row.get(sheet1.graphics_pivot_point_y);
int shapeWidth = row.get(sheet1.graphics_width);
int shapeHeight = row.get(sheet1.graphics_height);
//String aislename = row.get(sheet1.aisle);
RectangularWall rw = new RectangularWall();
rw.setSize(shapeWidth, shapeHeight);
rw.setPos(xPos, yPos, 0);
rw.setVisible(true);
rw.setOwner(this);
level.add(rw);
}
level.initialize();
presentation.add(level);
我目前有一个 PedSource、一个 PedGoTo 和一个接收器。还有一个带有 pedSource.inject() 的按钮作为测试它们如何在墙壁上移动的操作。
但是,当我单击按钮时,出现以下错误:
Exception during discrete event execution:
NullPointerException
java.lang.NullPointerException
at com.anylogic.engine.markup.BoundingRectangle.getMinX(Unknown Source)
at com.anylogic.libraries.modules.level_system.LevelDataBuilder.d(Unknown Source)
at com.anylogic.libraries.modules.level_system.LevelDataBuilder.b(Unknown Source)
at com.anylogic.libraries.modules.level_system.LevelDataStorage.a(Unknown Source)
at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1133)
at com.anylogic.libraries.modules.level_system.LevelDataStorage.getLevelData(Unknown Source)
at com.anylogic.libraries.pedestrian.an.<init>(Unknown Source)
at com.anylogic.libraries.pedestrian.PedLevel_xjal.j(Unknown Source)
at com.anylogic.libraries.pedestrian.PedSettings.a(Unknown Source)
at com.anylogic.libraries.pedestrian.PedEnter.c(Unknown Source)
at com.anylogic.libraries.pedestrian.PedEnter.a(Unknown Source)
at com.anylogic.libraries.pedestrian.PedEnter.process(Unknown Source)
at com.anylogic.libraries.pedestrian.PedEnter.a(Unknown Source)
at com.anylogic.libraries.pedestrian.PedEnter$2.onEnter(Unknown Source)
at com.anylogic.libraries.processmodeling.Delay.b(Unknown Source)
at com.anylogic.libraries.processmodeling.Delay$9.onEnter(Unknown Source)
at com.anylogic.libraries.processmodeling.InputBlock$1.b(Unknown Source)
at com.anylogic.libraries.processmodeling.InPort.a(Unknown Source)
at com.anylogic.libraries.processmodeling.InPort.receiveImmediately(Unknown Source)
at com.anylogic.libraries.processmodeling.InputBlock$1.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.b(Unknown Source)
at com.anylogic.libraries.processmodeling.OutPort.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutputBlock.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutputBlock$2.a(Unknown Source)
at com.anylogic.libraries.processmodeling.OutputBlock$2.action(Unknown Source)
at com.anylogic.libraries.processmodeling.AsynchronousExecutor_xjal$a.execute(Unknown Source)
at com.anylogic.engine.LibraryEventHandler$n.execute(Unknown Source)
at com.anylogic.engine.Engine.n(Unknown Source)
at com.anylogic.engine.Engine.cl(Unknown Source)
at com.anylogic.engine.Engine$n.run(Unknown Source)
如果我画一堵矩形墙,然后运行相同的代码,行人就会进入街区并遵循预期的行为。
因此,这导致我的代码存在问题,就像我创建的 pedSource 块和对象不在同一级别或类似的级别中。
我已经浏览了所有文档并进行了搜索,但我找不到解决方案或看到哪里出了问题。我希望有人能给我指出正确的方向,请谢谢。
就像我创建的 pedSource 块和对象不在同一级别或类似的东西
如果您显示的代码是所有关卡创建代码,则不会出现这种情况,因为您不会将创建的关卡存储在任何地方(它是该代码的本地代码)。您如何定义 PedSource 将行人添加到的级别?
我想这可以解决问题
将默认级别的名称更改为levelX。
在 main 或正在建造墙壁的位置创建一个名为 myLevel 的变量...该变量的初始值将是一个返回 Level 类型值的函数,您将在其中编写您正在使用的代码
在您的代码中,而不是使用
关卡 level = new Level(this, "mylevel", SHAPE_DRAW_2D3D, 0);
做
Level level = levelX;
您不再需要这些线路了
level.initialize();
presentation.add(level);
相反,您只需在其末尾返回 level 即可,因为所有内容都将位于返回该值的函数中......就像这样:
Level level = levelX;
List<Tuple> rows = selectFrom(sheet1)
.list();
for (Tuple row : rows) {
int xPos = row.get(sheet1.graphics_pivot_point_x);
int yPos = row.get(sheet1.graphics_pivot_point_y);
int shapeWidth = row.get(sheet1.graphics_width);
int shapeHeight = row.get(sheet1.graphics_height);
//String aislename = row.get(sheet1.aisle);
RectangularWall rw = new RectangularWall();
rw.setSize(shapeWidth, shapeHeight);
rw.setPos(xPos, yPos, 0);
rw.setVisible(true);
rw.setOwner(this);
level.add(rw);
}
return level;
没测试过,但希望能成功