使用Fact对象时出现Drools ksession.insert错误

时间:2018-11-19 11:22:51

标签: java drools

我计划使用FactTemplate而不是POJO基于JSON有效负载创建动态对象,但是在知识库中插入事实org.drools.core.facttemplates.Fact时出现错误。

  

java.lang.NullPointerException在   org.drools.core.phreak.PropagationEntry $ Insert.execute(PropagationEntry.java:134)     在   org.drools.reteoo.common.RetePropagationList.addEntry(RetePropagationList.java:36)     在   org.drools.core.impl.StatefulKnowledgeSessionImpl.addPropagation(StatefulKnowledgeSessionImpl.java:2095)     在   org.drools.reteoo.common.ReteWorkingMemory.addPropagation(ReteWorkingMemory.java:238)     在   org.drools.core.reteoo.EntryPointNode.assertObject(EntryPointNode.java:225)     在   org.drools.core.common.NamedEntryPoint.insert(NamedEntryPoint.java:278)     在   org.drools.core.common.NamedEntryPoint.insert(NamedEntryPoint.java:239)     在   org.drools.core.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:1535)     在   org.drools.reteoo.common.ReteWorkingMemory.insert(ReteWorkingMemory.java:285)     在   org.drools.core.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:1481)     在   org.drools.impl.adapters.KnowledgeRuntimeAdapter.insert(KnowledgeRuntimeAdapter.java:263)     在com.pexa.au.DroolsMain.main(DroolsMain.java:100)

这是我的代码:

InternalKnowledgePackage pkg = new KnowledgePackageImpl("test");
final FieldTemplate ft = new FieldTemplateImpl( "person",
                0,
                String.class );

final FieldTemplate[] fields1 = new FieldTemplate[]{ft};

final FactTemplate factTemplate = new FactTemplateImpl( pkg,
                "PersonDetails",
                fields1 );


 final Fact personFact = factTemplate.createFact( 10 );
 personFact.setFieldValue( "person",
       "NAMEE!!" );

 ksession.insert(personFact);

 ksession.fireAllRules();

任何建议将不胜感激! :)

0 个答案:

没有答案