Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在DRools规则中遍历空数组时出错_Java_Drools - Fatal编程技术网

Java 在DRools规则中遍历空数组时出错

Java 在DRools规则中遍历空数组时出错,java,drools,Java,Drools,我正在.drl规则文件中使用arrayList。 在一条规则中,我检查列表是否为空,并设置setFocus(第二条规则)。 在第二个规则中,我从列表中获取元素,在这个规则中,我获取的列表为空错误 我希望检查列表是否为空,并在一个规则中从该arraylist获取特定元素 rule "Rule chesks client had already received Notifications or Not" salience 10 no-loop true when event :

我正在.drl规则文件中使用arrayList。 在一条规则中,我检查列表是否为空,并设置setFocus(第二条规则)。 在第二个规则中,我从列表中获取元素,在这个规则中,我获取的列表为空错误

我希望检查列表是否为空,并在一个规则中从该arraylist获取特定元素

rule "Rule chesks client had already received Notifications or Not" 
salience 10   
no-loop true
when  
    event : Event($listOfClientNotifications : clientNotifications)
    eval($listOfClientNotifications < 1)   
then
    event.setMessage("list is null");
end  
rule“rule chesks客户端是否已收到通知”
显著性10
无循环为真
什么时候
事件:事件($listOfClientNotifications:clientNotifications)
eval($ListofClient通知<1)
然后
setMessage(“列表为空”);
结束
第二条规则:

rule "Rule chesks " 
salience 05   
no-loop true
when  
    event : Event($listOfClientNotifications : clientNotifications)
    value : ClientNotifications() from $listOfClientNotifications; // <<< !!!
then  
    event.setMessage("Value "+**value.getMessage()**);
end   
规则“规则检查”
显著性05
无循环为真
什么时候
事件:事件($listOfClientNotifications:clientNotifications)
值:$ListofClient Notifications中的ClientNotifications()// 在一个规则中针对null测试列表(正确!)并不能避免在另一个规则中遇到NPE。规则评估与规则执行、显著性和激活组不同步,也不重复

这是一个正确的检查:

rule "check list is null"
when  
    event : Event(clientNotifications == null)
then
    event.setMessage("list is null");
end
防止撞到NPE

rule "use notifications from list"
when  
    event : Event($listOfClientNotifications : clientNotifications != null)
    value : ClientNotifications() from $listOfClientNotifications;
then  
    event.setMessage("Value "+ value.getMessage()); // strange, but maybe?
end