简体   繁体   English

规则编译错误:只能迭代java.lang.Iterable的数组或实例

[英]Rule Compilation error : Can only iterate over an array or an instance of java.lang.Iterable

I am new to mongoDb and drools. 我是mongoDb和流口水的新手。 I am writing a rule in drools, which is iterating a java list. 我在流口水中写了一条规则,该规则正在迭代Java列表。 But when running tomcat it is giving Rule Compilation error. 但是当运行tomcat时,它会给出规则编译错误。

Getting List from dao :- 从dao获取列表:-

List<XYZ> list = new ArrayList<XYZ>();
Query q = query(where("id").is(userId));
list = getMongoOperation().find(q, XYZ.class, "XYZ"); 

Using list in drools engine Rule :- 在drools引擎中使用列表规则:-

for(XYZ xyzObj : list) 
{           
}

Model Class :- 型号类别:-

@Document(collection="XYZ")
public class XYZ 
{
}

I am getting exception when running tomcat. 运行tomcat时出现异常。 "Rule Compilation error : Can only iterate over an array or an instance of java.lang.Iterable" “规则编译错误:只能迭代数组或java.lang.Iterable的实例”

Rule File :- 规则文件:-

import java.util.List; 导入java.util.List; import java.util.Iterator; 导入java.util.Iterator; global com.demo.XYZ list 全局com.demo.XYZ列表

rule '1_Demo_Rule' 规则“ 1_Demo_Rule”

when prop : RULEDEMO( attribute == "demo") then 当prop时:RULEDEMO(attribute ==“ demo”)然后

  for(XYZ xyzObj : list) { } 

end 结束

You will not be able to use the short syntax of the for-statement at all, due to restrictions in the DRL parser. 由于DRL解析器中的限制,您将根本无法使用for语句的简短语法。

Given that 鉴于

global List<com.demo.XYZ> list;

use the not-so-nice 使用不太好

for( int i = 0; i < list.size(); i++ ){
    XYZ xyzObj = list.get(i);
    // ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在reducer中的for循环上获得编译错误“只能迭代数组或java.lang.Iterable实例” - Getting compilation error “Can only iterate over an array or an instance of java.lang.Iterable” at for loop in reducer 只能迭代一个数组或java.lang.Iterable的实例 - Can only iterate over an array or an instance of java.lang.Iterable 只能迭代java.lang.Iterable的数组或实例吗? - Can only iterate over an array or an instance of java.lang.Iterable? Eclipse 编译错误显示不正确(只能迭代数组或 java.lang.Iterable 的实例) - Eclipse compile error shown incorrectly (Can only iterate over an array or an instance of java.lang.Iterable) 错误:只能遍历数组或java.lang.Iterable的实例 - Error: can only iterate over an array or an instance of java.lang.Iterable 只能在java.lang.Iterable中的数组或实例上进行迭代 - Can only iterate over an array or an instance of java.lang.Iterable in java 使用FileUtils时只能迭代数组或java.lang.Iterable的实例 - Can only iterate over an array or an instance of java.lang.Iterable while using FileUtils 另一个“只能迭代数组或java.lang.Iterable的实例”问题 - Yet another “Can only iterate over an array or an instance of java.lang.Iterable” issue ForStatement-只能迭代数组或java.lang的实例。在csv文件创建中可迭代 - ForStatement - Can only iterate over an array or an instance of java.lang.Iterable in csv file creation 我正在使用Collection只能迭代数组或java.lang.Iterable的实例 - i am using Collection Can only iterate over an array or an instance of java.lang.Iterable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM