英文:
Why getting NullPointerException error in AnyLogic while using wait block?
问题
我有一个名为"client"的代理,其中包含3个变量(初始值都为false):
- var_puttingFreeService
- var_massageService
- var_simulatorService
现在在主程序中,我创建了一个每1分钟重复一次的"event"。此事件检查wait.size > 1
并且任何服务为空时,如果对于此代理所有上述提到的变量值都为false,则释放来自"wait"的第一个代理。
但是,即使"wait"块不为空,我仍然收到"NullPointerException"错误。
请告诉我我在哪里出错了。
英文:
I have a agent "client" which contain 3 variables (all are initially false)
- var_puttingFreeService
- var_massageService
- var_simulatorService
Now in the Main, I create an "event" which repeat in every 1 minute.
This event check if wait.size > 1
and any service is empty, then free the first agent from "wait" if all the above mentioned variable values are false for this agent.
But i am getting "NullPointerException" error even though the wait block is not empty.
Kindly let me know where I am making mistake.
答案1
得分: 1
你需要明白的是:
false && false || true || false
是真的
你需要适当地使用括号,&& 优先级高于 ||
所以你应该这样做:
if (wait.size() > 1 && (delay1.size() == 0 || delay2.size() == 0))
你看到区别了吗?
英文:
what you need to understand is that
false && false || true || false
is true
you need to use parenthesis appropriately and the && takes precence over the ||
so you should do
if (wait.size()>1 && (delay1.size()==0 || delay2.size()==0))
you see the difference?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论