cancel
Showing results for 
Search instead for 
Did you mean: 

Null pointer exception

habibhalaoui
Champ in-the-making
Champ in-the-making
hello I can not solve this problem of nullpinterExeption, how to have the value of loan Amount
How can I read the value of the form LoanAmount  form ProcessStartExecutionListener class?

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.bpmnwithactiviti.org/loanrequest">
  <process id="loanrequest" name="Process to handle a loan request" isExecutable="true">
  <extensionElements>
     <activiti:executionListener class="org.bpmnwithactiviti.chapter5.listener.ProcessStartExecutionListener" event="start" />
         <activiti:executionListener class="org.bpmnwithactiviti.chapter5.listener.ProcessEndExecutionListener" event="end" />
       </extensionElements>
    <startEvent id="theStart" >
      <extensionElements>
        <activiti:formProperty id="name" name="Name" type="string" required="true"></activiti:formProperty>
        <activiti:formProperty id="emailAddress" name="Email address" type="string" required="true"></activiti:formProperty>
        <activiti:formProperty id="income" name="Income" type="long" required="true"></activiti:formProperty>
        <activiti:formProperty id="loanAmount" name="Loan amount" type="long" required="true" ></activiti:formProperty>
         
      </extensionElements>
    </startEvent>
   
    <sequenceFlow id="sequenceFlow-d450f4a5-4e6f-4b3e-8451-07228a5b1b0d" sourceRef="theStart" targetRef="checkCredit"></sequenceFlow>
    <scriptTask id="checkCredit" scriptFormat="groovy" activiti:autoStoreVariables="true">
      <script>
            out:println "Checking credit for " + name;
            creditCheckOk = false;
            if((income / 2) &gt; loanAmount){
               creditCheckOk = true;
            }
            out:println "Checked credit for " + name + " outcome is " + creditCheckOk;
         </script>
    </scriptTask>
    <sequenceFlow id="sequenceFlow-b5777c55-420a-426c-9245-44fcb83e4df4" sourceRef="checkCredit" targetRef="createApplication"></sequenceFlow>
    <serviceTask id="createApplication" activiti:class="org.bpmnwithactiviti.chapter5.CreateApplicationTask"></serviceTask>
    <sequenceFlow id="sequenceFlow-a205db56-b336-492d-92b1-3c7996441546" sourceRef="createApplication" targetRef="evaluateLoanRequest"></sequenceFlow>
    <userTask id="evaluateLoanRequest" name="Evaluate loan request" activiti:assignee="fozzie">
      <extensionElements>
        <activiti:formProperty id="customerName" name="Customer name" expression="${loanApplication.customerName}" writable="false"></activiti:formProperty>
        <activiti:formProperty id="income" name="Income of customer" expression="${loanApplication.income}" writable="false"></activiti:formProperty>
        <activiti:formProperty id="requestedAmount" name="Requested loan amount" expression="${loanApplication.requestedAmount}" writable="false"></activiti:formProperty>
        <activiti:formProperty id="creditCheckOk" name="Outcome of credit check" expression="${loanApplication.creditCheckOk}" writable="false"></activiti:formProperty>
        <activiti:formProperty id="requestApproved" name="Do you approve the request?" type="enum" required="true">
          <activiti:value id="true" name="Yes"></activiti:value>
          <activiti:value id="false" name="No"></activiti:value>
        </activiti:formProperty>
        <activiti:formProperty id="explanation" name="Explanation"></activiti:formProperty>
      </extensionElements>
    </userTask>
    <sequenceFlow id="sequenceFlow-bb80e463-aeaa-400f-b4e0-93411ebf9d03" sourceRef="evaluateLoanRequest" targetRef="approvalGateway"></sequenceFlow>
    <boundaryEvent id="escalationTimer" attachedToRef="evaluateLoanRequest" cancelActivity="true">
      <timerEventDefinition>
        <timeDuration>PT1M</timeDuration>
      </timerEventDefinition>
    </boundaryEvent>
    <sequenceFlow id="sequenceFlow-e77d6d4d-9c90-4abe-979b-55562296a412" sourceRef="escalationTimer" targetRef="evaluateRequestByManager"></sequenceFlow>
    <userTask id="evaluateRequestByManager" name="Evaluate loan request by manager" activiti:candidateGroups="management">
      <extensionElements>
        <activiti:formProperty id="customerName" name="Customer name" expression="${loanApplication.customerName}" writable="false"></activiti:formProperty>
        <activiti:formProperty id="income" name="Income of customer" expression="${loanApplication.income}" writable="false"></activiti:formProperty>
        <activiti:formProperty id="requestedAmount" name="Requested loan amount" expression="${loanApplication.requestedAmount}" writable="false"></activiti:formProperty>
        <activiti:formProperty id="creditCheckOk" name="Outcome of credit check" expression="${loanApplication.creditCheckOk}" writable="false"></activiti:formProperty>
        <activiti:formProperty id="requestApproved" name="Do you approve the request?" type="enum" required="true">
          <activiti:value id="true" name="Yes"></activiti:value>
          <activiti:value id="false" name="No"></activiti:value>
        </activiti:formProperty>
        <activiti:formProperty id="explanation" name="Explanation"></activiti:formProperty>
      </extensionElements>
    </userTask>
    <sequenceFlow id="sequenceFlow-d94c0587-5717-4229-a236-c861b3cfcf36" sourceRef="evaluateRequestByManager" targetRef="approvalGateway"></sequenceFlow>
    <exclusiveGateway id="approvalGateway"></exclusiveGateway>
    <sequenceFlow id="sequenceFlow-8146a86e-12d1-4a93-9e2d-a48daa266830" sourceRef="approvalGateway" targetRef="informCustomer">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${requestApproved == false}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="sequenceFlow-298593fc-ef06-49cc-8714-e4d8cf9de075" sourceRef="approvalGateway" targetRef="processRequest">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${requestApproved == true}]]></conditionExpression>
    </sequenceFlow>
    <serviceTask id="informCustomer" activiti:type="mail">
      <extensionElements>
        <activiti:field name="to">
          <activiti:expression>${loanApplication.emailAddress}</activiti:expression>
        </activiti:field>
        <activiti:field name="subject">
          <activiti:string>Loan Request Denied</activiti:string>
        </activiti:field>
        <activiti:field name="html">
          <activiti:expression>&lt;html&gt;
                &lt;body&gt;
                  Hello ${loanApplication.customerName},&lt;br/&gt;&lt;br/&gt;
                 
                  Your loan request has been denied for the following reason: ${explanation}.&lt;br/&gt;&lt;br/&gt;
                 
                  Kind regards,&lt;br/&gt;
                 
                  The Loan Sharks Company.
                &lt;/body&gt;
              &lt;/html&gt;</activiti:expression>
        </activiti:field>
      </extensionElements>
    </serviceTask>
    <sequenceFlow id="sequenceFlow-d47de415-a158-43f4-8a68-6c28a92011c2" sourceRef="informCustomer" targetRef="theEnd"></sequenceFlow>
    <userTask id="processRequest" name="Process the loan request" activiti:assignee="fozzie"></userTask>
    <sequenceFlow id="sequenceFlow-7c3caf15-06b9-4a7b-880a-a19977c7c4c8" sourceRef="processRequest" targetRef="theEnd"></sequenceFlow>
    <endEvent id="theEnd"></endEvent>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_loanrequest">
    <bpmndi:BPMNPlane bpmnElement="loanrequest" id="BPMNPlane_loanrequest">
      <bpmndi:BPMNShape bpmnElement="escalationTimer" id="BPMNShape_escalationTimer">
        <omgdc:Bounds height="30.0" width="30.0" x="445.0" y="45.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="createApplication" id="BPMNShape_createApplication">
        <omgdc:Bounds height="60.0" width="100.0" x="230.0" y="4.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="processRequest" id="BPMNShape_processRequest">
        <omgdc:Bounds height="60.0" width="100.0" x="620.0" y="0.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="evaluateRequestByManager" id="BPMNShape_evaluateRequestByManager">
        <omgdc:Bounds height="60.0" width="140.0" x="340.0" y="160.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="informCustomer" id="BPMNShape_informCustomer">
        <omgdc:Bounds height="60.0" width="100.0" x="620.0" y="160.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="evaluateLoanRequest" id="BPMNShape_evaluateLoanRequest">
        <omgdc:Bounds height="60.0" width="100.0" x="380.0" y="0.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="approvalGateway" id="BPMNShape_approvalGateway">
        <omgdc:Bounds height="40.0" width="40.0" x="530.0" y="90.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="theEnd" id="BPMNShape_theEnd">
        <omgdc:Bounds height="35.0" width="35.0" x="770.0" y="95.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="checkCredit" id="BPMNShape_checkCredit">
        <omgdc:Bounds height="60.0" width="100.0" x="80.0" y="6.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="theStart" id="BPMNShape_theStart">
        <omgdc:Bounds height="35.0" width="35.0" x="0.0" y="21.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sequenceFlow-298593fc-ef06-49cc-8714-e4d8cf9de075" id="BPMNEdge_sequenceFlow-298593fc-ef06-49cc-8714-e4d8cf9de075">
        <omgdi:waypoint x="570.0" y="110.0"></omgdi:waypoint>
        <omgdi:waypoint x="582.0" y="110.0"></omgdi:waypoint>
        <omgdi:waypoint x="582.0" y="30.0"></omgdi:waypoint>
        <omgdi:waypoint x="620.0" y="30.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sequenceFlow-b5777c55-420a-426c-9245-44fcb83e4df4" id="BPMNEdge_sequenceFlow-b5777c55-420a-426c-9245-44fcb83e4df4">
        <omgdi:waypoint x="180.0" y="36.0"></omgdi:waypoint>
        <omgdi:waypoint x="192.0" y="36.0"></omgdi:waypoint>
        <omgdi:waypoint x="192.0" y="34.0"></omgdi:waypoint>
        <omgdi:waypoint x="230.0" y="34.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sequenceFlow-d450f4a5-4e6f-4b3e-8451-07228a5b1b0d" id="BPMNEdge_sequenceFlow-d450f4a5-4e6f-4b3e-8451-07228a5b1b0d">
        <omgdi:waypoint x="35.0" y="38.0"></omgdi:waypoint>
        <omgdi:waypoint x="42.0" y="36.0"></omgdi:waypoint>
        <omgdi:waypoint x="42.0" y="36.0"></omgdi:waypoint>
        <omgdi:waypoint x="80.0" y="36.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sequenceFlow-e77d6d4d-9c90-4abe-979b-55562296a412" id="BPMNEdge_sequenceFlow-e77d6d4d-9c90-4abe-979b-55562296a412">
        <omgdi:waypoint x="460.0" y="75.0"></omgdi:waypoint>
        <omgdi:waypoint x="460.0" y="117.0"></omgdi:waypoint>
        <omgdi:waypoint x="490.0" y="117.0"></omgdi:waypoint>
        <omgdi:waypoint x="490.0" y="230.0"></omgdi:waypoint>
        <omgdi:waypoint x="430.0" y="230.0"></omgdi:waypoint>
        <omgdi:waypoint x="410.0" y="220.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sequenceFlow-8146a86e-12d1-4a93-9e2d-a48daa266830" id="BPMNEdge_sequenceFlow-8146a86e-12d1-4a93-9e2d-a48daa266830">
        <omgdi:waypoint x="570.0" y="110.0"></omgdi:waypoint>
        <omgdi:waypoint x="582.0" y="110.0"></omgdi:waypoint>
        <omgdi:waypoint x="582.0" y="190.0"></omgdi:waypoint>
        <omgdi:waypoint x="620.0" y="190.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sequenceFlow-d47de415-a158-43f4-8a68-6c28a92011c2" id="BPMNEdge_sequenceFlow-d47de415-a158-43f4-8a68-6c28a92011c2">
        <omgdi:waypoint x="720.0" y="190.0"></omgdi:waypoint>
        <omgdi:waypoint x="732.0" y="190.0"></omgdi:waypoint>
        <omgdi:waypoint x="732.0" y="110.0"></omgdi:waypoint>
        <omgdi:waypoint x="770.0" y="112.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sequenceFlow-d94c0587-5717-4229-a236-c861b3cfcf36" id="BPMNEdge_sequenceFlow-d94c0587-5717-4229-a236-c861b3cfcf36">
        <omgdi:waypoint x="480.0" y="190.0"></omgdi:waypoint>
        <omgdi:waypoint x="492.0" y="190.0"></omgdi:waypoint>
        <omgdi:waypoint x="492.0" y="110.0"></omgdi:waypoint>
        <omgdi:waypoint x="530.0" y="110.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sequenceFlow-bb80e463-aeaa-400f-b4e0-93411ebf9d03" id="BPMNEdge_sequenceFlow-bb80e463-aeaa-400f-b4e0-93411ebf9d03">
        <omgdi:waypoint x="480.0" y="30.0"></omgdi:waypoint>
        <omgdi:waypoint x="492.0" y="30.0"></omgdi:waypoint>
        <omgdi:waypoint x="492.0" y="110.0"></omgdi:waypoint>
        <omgdi:waypoint x="530.0" y="110.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sequenceFlow-a205db56-b336-492d-92b1-3c7996441546" id="BPMNEdge_sequenceFlow-a205db56-b336-492d-92b1-3c7996441546">
        <omgdi:waypoint x="330.0" y="34.0"></omgdi:waypoint>
        <omgdi:waypoint x="342.0" y="34.0"></omgdi:waypoint>
        <omgdi:waypoint x="342.0" y="30.0"></omgdi:waypoint>
        <omgdi:waypoint x="380.0" y="30.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sequenceFlow-7c3caf15-06b9-4a7b-880a-a19977c7c4c8" id="BPMNEdge_sequenceFlow-7c3caf15-06b9-4a7b-880a-a19977c7c4c8">
        <omgdi:waypoint x="720.0" y="30.0"></omgdi:waypoint>
        <omgdi:waypoint x="732.0" y="30.0"></omgdi:waypoint>
        <omgdi:waypoint x="732.0" y="110.0"></omgdi:waypoint>
        <omgdi:waypoint x="770.0" y="112.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

<h1>LoanApplication.java</h1>
public class LoanApplication implements Serializable {

   private static final long serialVersionUID = 1L;
   
   private String customerName;
   private long income;
   private long requestedAmount;
   private boolean creditCheckOk;
   private String explanation;
   private String emailAddress;
   private long loanAmount;
   
   public String getCustomerName() {
     return customerName;
  }
   public void setCustomerName(String customerName) {
     this.customerName = customerName;
  }
   public long getIncome() {
     return income;
  }
   public void setloanAmount(long loanamount) {
     this.loanAmount = loanamount;
  }
   public long getloanAmount() {
        return loanAmount;
     }
      public void setIncome(long income) {
        this.income = income;
     }
   public long getRequestedAmount() {
     return requestedAmount;
  }
   public void setRequestedAmount(long requestedAmount) {
     this.requestedAmount = requestedAmount;
  }
   public boolean isCreditCheckOk() {
     return creditCheckOk;
  }
   public void setCreditCheckOk(boolean creditCheckOk) {
     this.creditCheckOk = creditCheckOk;
  }
   public String getExplanation() {
     return explanation;
  }
   public void setExplanation(String explanation) {
     this.explanation = explanation;
  }
   public String getEmailAddress() {
     return emailAddress;
  }
   public void setEmailAddress(String emailAddress) {
     this.emailAddress = emailAddress;
  }
}


<h1>CreateApplicationTask.java</h1>
public class CreateApplicationTask implements JavaDelegate {

   public void execute(DelegateExecution execution) {
      LoanApplication la = new LoanApplication();
      la.setCreditCheckOk((Boolean) execution.getVariable("creditCheckOk"));
      la.setCustomerName((String) execution.getVariable("name"));
      la.setIncome((Long) execution.getVariable("income"));
      la.setRequestedAmount((Long) execution.getVariable("loanAmount"));
      la.setEmailAddress((String) execution.getVariable("emailAddress"));
      execution.setVariable("loanApplication", la);
   }
}

<h1>ProcessStartExecutionListener.java</h1>
public class ProcessStartExecutionListener implements ExecutionListener {


   @Override
   public void notify(DelegateExecution execution) throws Exception {
      
      LoanRequestReceivedEvent event = new LoanRequestReceivedEvent(
         execution.getId(),
         new Date().getTime(),
         (Integer) execution.getVariable("loanAmount"));
      
      EventSender.send(event);
   }
}

<h1>ProcessEndEvent.java</h1>
public class ProcessEndExecutionListener implements ExecutionListener {

   @Override
   public void notify(DelegateExecution execution) throws Exception {
      LoanRequestProcessedEvent event = new LoanRequestProcessedEvent (
         execution.getId(),
         new Date().getTime(),
         (Boolean) execution.getVariable("requestApproved"),
         10);
      EventSender.send(event);
   }
}
5 REPLIES 5

jbarrez
Star Contributor
Star Contributor
Where do you get the nullpointer? A stacktrace would help here a lot (cause I see a lot of code that uses LoanAmount, but don't know where exactly it might go wrong)

habibhalaoui
Champ in-the-making
Champ in-the-making
with class exection listener Start Process Execution listener.java >>
Null pointerExeption in this line :
execution.getvariable("loanAmount")

jbarrez
Star Contributor
Star Contributor
Ok, I see. Could you verify whether the execution is null or the result of execution.getVariable() is null?

habibhalaoui
Champ in-the-making
Champ in-the-making
When i  try execution.getVariableNames() i get in return an empty table"

jbarrez
Star Contributor
Star Contributor
Ok. So how do you start your process instance? I don't see the code where you actually pass the values? Are you filling these in in Activiti Explorer with forms?