Hello all,
I'm getting a NullPointerException when calling
org.kie.api.definition.type.FactType.set(Object, String, Object) and also when I call
org.kie.api.definition.type.FactType.setFromMap(Object, Map<String, Object>). The
exception stack trace points to the same line in both cases:
Exception in thread "main" java.lang.NullPointerException
at org.drools.core.factmodel.ClassDefinition.set(ClassDefinition.java:255)
...
Doing some debugging, I found that the getFieldAccessor() call in
org.drools.core.factmodel.ClassDefinition, line 255, is returning null, which is
what's causing this. I didn't dig deeper than that, though.
I created the data model in Drools Workbench 6.0.1 final and I've double-checked that
the field I'm passing in to set a value exists on the object. Below is my code and
it's throwing the NPE on the last line.
I'm going to try to use standard Java reflection instead for now, but any assistance
on this would be appreciated. I can provide any other code, the KieModule JAR produced by
Workbench, or anything else, if needed.
KieServices ks = KieServices.Factory.get();
KieContainer kContainer =
ks.newKieContainer(ks.newReleaseId("com.hp.pa.sample", "realestate",
"LATEST"));
KieSession kSession = kContainer.newKieSession();
KieBase kBase = kSession.getKieBase();
FactType agentAssignmentType =
kBase.getFactType("com.hp.pa.sample.realestate",
"AgentAssignmentData");
FactType property4SaleType =
kBase.getFactType("com.hp.pa.sample.realestate", "PropertyForSale");
if (agentAssignmentType == null || property4SaleType == null)
System.err.println("Could not find a FactType");
Object agentAssignment = null;
Object property4Sale = null;
try {
agentAssignment = agentAssignmentType.newInstance();
property4Sale = property4SaleType.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
property4SaleType.set(property4Sale, "city", "San Diego");
Thank you,
Ronak Patel
Software Designer
HP Autonomy