There is probably something wrong with your drl.
Try starting from an empty drl file and then add each of the rules and definitions in it
one by one until you find the one causing problems. Then you can produce a test case and
create a JIRA issue for it if it doesn't already exist - as it should at least be
giving a useful error message and not throwing a null pointer exception.
Thomas
From: rules-users-bounces(a)lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On
Behalf Of Roger Smith
Sent: 09 November 2010 06:41
To: rules-users(a)lists.jboss.org
Subject: [rules-users] NullPointerException when using Drools rule template
All -
I tried out Drools rule template with a with a proptotype app. Drools is throwing
NullPointerException as below. I would much appreciate if someone on this list can help.
java.lang.NullPointerException
at
org.drools.template.parser.DefaultTemplateColumn.createCellCondition(DefaultTemplateColumn.java:68)
at
org.drools.template.parser.DefaultTemplateColumn.addCondition(DefaultTemplateColumn.java:91)
at
org.drools.template.parser.DefaultTemplateRuleBase.createColumnConditions(DefaultTemplateRuleBase.java:105)
at
org.drools.template.parser.DefaultTemplateRuleBase.createTemplateRule(DefaultTemplateRuleBase.java:98)
at
org.drools.template.parser.DefaultTemplateRuleBase.getDTRules(DefaultTemplateRuleBase.java:85)
at
org.drools.template.parser.DefaultTemplateRuleBase.<init>(DefaultTemplateRuleBase.java:64)
at
org.drools.template.parser.TemplateDataListener.<init>(TemplateDataListener.java:76)
at
org.drools.template.parser.TemplateDataListener.<init>(TemplateDataListener.java:52)
at org.drools.template.ObjectDataCompiler.compile(ObjectDataCompiler.java:44)
Here is my code
KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
ObjectDataCompiler converter = new ObjectDataCompiler();
InputStream dis = new FileInputStream( new File(
"/home/pranab/Projects/gridx/ct11_1.drl" ) );
if (null == dis){
System.out.println("null rule template stream");
return;
}
Collection<Map<String,Object>> paramMaps = new
ArrayList<Map<String,Object>>();
Map<String,Object> params = new HashMap<String,Object>();
params.put("summerOnPeakPrimaryRate", new Integer(299));
params.put("summerOnPeakSecondaryRate", new Integer(524));
params.put("summerSemiPeakPrimaryRate", new Integer(176));
params.put("summerSemiPeakSecondaryRate", new Integer(305));
params.put("summerOffPeakPrimaryRate", new Integer(139));
params.put("summerOffPeakSecondaryRate", new Integer(243));
params.put("winterOnPeakPrimaryRate", new Integer(249));
params.put("winterOnPeakSecondaryRate", new Integer(438));
params.put("winterSemiPeakPrimaryRate", new Integer(176));
params.put("winterSemiPeakSecondaryRate", new Integer(305));
params.put("winterOffPeakPrimaryRate", new Integer(139));
params.put("winterOffPeakSecondaryRate", new Integer(243));
paramMaps.add(params);
String drl = converter.compile(paramMaps, dis);
Reader rdr = new StringReader( drl );
kBuilder.add( ResourceFactory.newReaderResource(rdr), ResourceType.DRL);
The line in blue is throwing the exception. This code is very similar to the example code
in Drools Expert guide.
Best,
Roger
________________________________
**************************************************************************************
This message is confidential and intended only for the addressee. If you have received
this message in error, please immediately notify the postmaster(a)nds.com and delete it from
your system as well as any copies. The content of e-mails as well as traffic data may be
monitored by NDS for employment and security purposes. To protect the environment please
do not print this e-mail unless necessary.
NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United
Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603
8808 40-00
**************************************************************************************