在使用 readObject() 从文件中读取集合后添加集合时出现异常
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 );
我认为这个错误可能是由于一个规则,但是如果我kbase.addKnowledgePackages()
从 drl 文件中读取规则后运行,不会有异常。
我的环境是 eclipse 3.7,java 7.0.21 y drools 5.5.0。
此致。
更新 1
使用 java 7.0.05 和 7.0.07 执行测试:错误仍然存在