[rules-users] java.lang.NullPointerException in simple example

ahgiovanini ahgiovanini at gmail.com
Tue Feb 18 19:52:22 EST 2014


Hi guys! 

I'm new in the world of jboss and drools and I'm making some simple examples
that existing on
https://github.com/droolsjbpm/drools/tree/master/drools-examples-api

Now, I'm studing the CashFlow example and in my project when I run it, I
receive a error message saying: 
Exception in thread "main" java.lang.NullPointerException
	at com.sample.CashFlowMain.main(CashFlowMain.java:30)"

I don't know the why this message, because I set the acp at lines 20 and 21.

Someone would help me please?

Thanks


package com.sample;

import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.rule.FactHandle;

import java.text.SimpleDateFormat;
import java.util.Date;

public class CashFlowMain {

    public static void main(String[] args) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        KieContainer kc =
KieServices.Factory.get().getKieClasspathContainer();
        KieSession ksession = kc.newKieSession("CashFlowKS");

        AccountPeriod acp = new AccountPeriod();
        acp.setStart(date("2013-01-01"));  // set acp - line 20
        acp.setEnd(date("2013-03-31"));    // set acp - line 21
        
        Account ac = new Account(1, 0);

        CashFlow cf1 = new CashFlow(date( "2013-01-12"), 100,
CashFlowType.CREDIT, 1 );
        CashFlow cf2 = new CashFlow(date( "2013-02-2"), 200,
CashFlowType.DEBIT, 1 );
        CashFlow cf3 = new CashFlow(date( "2013-05-18"), 50,
CashFlowType.CREDIT, 1 );
        CashFlow cf4 = new CashFlow(date( "2013-03-07"), 75,
CashFlowType.CREDIT, 1 );

        FactHandle fh = ksession.insert(acp);
        ksession.insert( ac );

        ksession.insert( cf1 );
        ksession.insert( cf2 );
        ksession.insert( cf3 );
        ksession.insert( cf4 );

        ksession.fireAllRules();

        acp.setStart(date( "2013-04-01"));
        acp.setEnd(date( "2013-06-31"));
        ksession.update(fh, acp);


        ksession.fireAllRules();
    }

    public static Date date(String str) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        return sdf.parse( str );
    }


}





--
View this message in context: http://drools.46999.n3.nabble.com/java-lang-NullPointerException-in-simple-example-tp4028177.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list