[rules-users] Get fact type returning null

kavita kavithasethu at gmail.com
Tue Jan 17 15:21:19 EST 2012


Hi,

I am a beginner to drools and am trying to integrate drools rules to java .
Am doing this using changeset. 
Here's my piece of code:

package edu.arizona;

import org.drools.KnowledgeBase;

import org.drools.agent.KnowledgeAgent;
import org.drools.agent.KnowledgeAgentFactory;

import org.drools.definition.type.FactType;
import org.drools.io.Resource;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;

public class TestRest {
	 public static void main(String[] args) throws
InstantiationException,IllegalAccessException {
		 StatefulKnowledgeSession ksession = null;
		   KnowledgeBase kbase = readKnowledgeBase();
		  
		   FactType factType = kbase.getFactType("edu.arizona", "result");
		   System.out.println (factType);
			Object obj = factType.newInstance();
		
			factType.set(obj,"rawConcentration",150);

			
			ksession = kbase.newStatefulKnowledgeSession();
			ksession.insert(obj);
			
			ksession.fireAllRules();
			
			System.out.println(factType.get(obj,"rescode"));
			
		 }
	 private static KnowledgeBase readKnowledgeBase() {
	        KnowledgeAgent kagent =
KnowledgeAgentFactory.newKnowledgeAgent("LabAgent");
	        Resource changeset = ResourceFactory.newClassPathResource(
	                "edu.arizona/lab-changeset.xml");
	        kagent.applyChangeSet(changeset);
	        KnowledgeBase kbase = kagent.getKnowledgeBase();
	        
	        kagent.dispose();
	        return kbase;
	    }
}


When i run the application the  System.out.println (factType) is printing as
null.  and getting 

Exception in thread "main" java.lang.NullPointerException
	at edu.arizona.TestRest.main(TestRest.java:20)

What am i missing? Please help.

Thanks,
Kavitha.


--
View this message in context: http://drools.46999.n3.nabble.com/Get-fact-type-returning-null-tp3667266p3667266.html
Sent from the Drools: User forum mailing list archive at Nabble.com.



More information about the rules-users mailing list