我在使用readObject()
从文件中读取后添加Collection时遇到异常java.lang.NullPointerException
at java.lang.Class.isAssignableFrom(Native Method)
at org.drools.base.ClassObjectType.isAssignableFrom(ClassObjectType.java:180)
at org.drools.reteoo.builder.PatternBuilder.attachPattern(PatternBuilder.java:95)
at org.drools.reteoo.builder.PatternBuilder.build(PatternBuilder.java:80)
at org.drools.reteoo.builder.GroupElementBuilder$AndBuilder.build(GroupElementBuilder.java:112)
at org.drools.reteoo.builder.GroupElementBuilder.build(GroupElementBuilder.java:70)
at org.drools.reteoo.builder.ReteooRuleBuilder.addSubRule(ReteooRuleBuilder.java:161)
at org.drools.reteoo.builder.ReteooRuleBuilder.addRule(ReteooRuleBuilder.java:134)
at org.drools.reteoo.ReteooBuilder.addRule(ReteooBuilder.java:113)
at org.drools.reteoo.ReteooRuleBase.addRule(ReteooRuleBase.java:445)
at org.drools.common.AbstractRuleBase.addRule(AbstractRuleBase.java:952)
at org.drools.common.AbstractRuleBase.addPackages(AbstractRuleBase.java:629)
at org.drools.reteoo.ReteooRuleBase.addPackages(ReteooRuleBase.java:472)
at org.drools.impl.KnowledgeBaseImpl.addKnowledgePackages(KnowledgeBaseImpl.java:149)
at DroolsEmpresa.readKnowledgeBaseFromMemoryFile(DroolsEmpresa.java:304)
at ServidorMR.cargaInfoConocimiento(ServidorMR.java:483)
at Tester.main(Tester.java:127)
序列化对象的代码是
ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream( fileName ) );
out.writeObject( kbuilder.getKnowledgePackages());
out.close();
反序列化的代码是
ObjectInputStream in = new ObjectInputStream( new FileInputStream( fileName) );
Collection<KnowledgePackage> kpkgs = (Collection<KnowledgePackage>)in.readObject();
in.close();
kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kpkgs );
我认为这个错误可能是由于规则造成的,但如果我在从drl文件中读取规则后运行kbase.addKnowledgePackages()
,则不会有异常。
我的环境是eclipse 3.7,java 7.0.21 y drools 5.5.0。
最诚挚的问候。
更新1
使用java 7.0.05和7.0.07执行测试:错误仍然存在
答案 0 :(得分:0)
最后问题是由于像这样的规则
...
when
a: Concept(...)
b: Concept(...)
or b: Concept(...)
and (eval(...) or eval(...))
then
...
解决方案在括号中加上第一个或。