[rules-users] Get fact type returning null

Wolfgang Laun wolfgang.laun at gmail.com
Wed Jan 18 03:03:42 EST 2012


A class edu.arizona.result is not to be seen (at least for me), and that's why
getFactType() returns null.

Does it work when you create a KnowlegeBase from DRL?

Is Resource changeset != null?

-W



On 17/01/2012, kavita <kavithasethu at gmail.com> wrote:
> 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.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



More information about the rules-users mailing list