AnyLogic仿真软件Java代码生成错误解决方案

模型概述

这是一个地铁站行人行为建模的模型,使用了行人库、扶梯、上下层等智能体建模。总共分为两层,B1层完成行人的进站和查验行李、上下梯行为,B2层完成行人上下梯的行为。

B1层

仿真软件 anylogic 生成的Java代码 anylogic模型创建时发生错误_scala

B2层

仿真软件 anylogic 生成的Java代码 anylogic模型创建时发生错误_scala_02

问题描述

其实问题真的很简单,,大概就是在模型运行的过程中发现跑不动了,然后显示下面的报错信息。

登录后复制


Index 0 out of bounds for length 0

java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0

	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)

	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)

	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)

	at java.base/java.util.Objects.checkIndex(Objects.java:372)

	at java.base/java.util.ArrayList.get(ArrayList.java:458)

	at com.anylogic.libraries.pedestrian.PedEscalators_xjal.a(Unknown Source)

	at com.anylogic.libraries.pedestrian.PedEscalators_xjal.c(Unknown Source)

	at com.anylogic.libraries.pedestrian.PedEscalators_xjal.c(Unknown Source)

	at com.anylogic.libraries.pedestrian.PedEscalators_xjal$4.choice(Unknown Source)

	at com.anylogic.libraries.processmodeling.SelectOutputIn.b(Unknown Source)

	at com.anylogic.libraries.processmodeling.SelectOutputIn$1.outputBlock(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.PlainTransfer$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.OutputBlock.forwardReadyEntityNotification(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.PlainTransfer$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.PlainTransfer$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.OutputBlock.forwardReadyEntityNotification(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.OutputBlock.forwardReadyEntityNotification(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.PlainTransfer$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.OutputBlock.forwardReadyEntityNotification(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.PlainTransfer$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.PlainTransfer$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$a.execute(Unknown Source)

	at com.anylogic.engine.Engine.h(Unknown Source)

	at com.anylogic.engine.Engine.nj(Unknown Source)

	at com.anylogic.engine.Engine$a.run(Unknown Source)
	
	

问题原因排查

这样的报错信息,首先找不到是出现在什么智能体上面,二是给出的报错信息,要么来自java原生包的、要么来自于anylogic的实例化函数(用户不可调),再看问题:Index 0 out of bounds for length 0。怎么说咱java也写了这么长时间了,可太熟悉这个了。

第一步 检查所有的定义循环、collection、queue的位置的逻辑是否正确

检查完之后发现所有元件,内部的语句都是没问题的。到这里我觉得够奇怪的了,但是这里的报错还好有指向性,那就是 Pedestrian Escalator(行人扶梯)的模块出了问题。

第二步 检查所有行人扶梯的设置是否正确

根据错误提示,这个模块的某个方法在执行时发生了“IndexOutOfBoundsException”的异常,也就是说它试图访问一个数组、列表或集合中不存在的元素。错误信息中显示“Index 0 out of bounds for length 0”,也就是说该模块的某个方法尝试获取一个长度为0的数组或列表中的第一个元素,这听起来就是有问题的,那么重点在于为什么这个长度为0。
对于扶梯组,如果让长度为0还要获取智能体,在测试中我能想到的只有扶梯方向设置反了

最后再排查的时候发现,扶梯组设置的方向错了(据说小伙伴排查了一晚上,可能是当局者迷了)。请注意:扶梯组一个方向只能做一件事!(这个就跟我们生活中的逻辑一模一样)

   

免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删

QR Code
微信扫一扫,欢迎咨询~

联系我们
武汉格发信息技术有限公司
湖北省武汉市经开区科技园西路6号103孵化器
电话:155-2731-8020 座机:027-59821821
邮件:tanzw@gofarlic.com
Copyright © 2023 Gofarsoft Co.,Ltd. 保留所有权利
遇到许可问题?该如何解决!?
评估许可证实际采购量? 
不清楚软件许可证使用数据? 
收到软件厂商律师函!?  
想要少购买点许可证,节省费用? 
收到软件厂商侵权通告!?  
有正版license,但许可证不够用,需要新购? 
联系方式 155-2731-8020
预留信息,一起解决您的问题
* 姓名:
* 手机:

* 公司名称:

姓名不为空

手机不正确

公司不为空