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 ie have the value of loan Amount
the XML file
<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>
            outSmiley Tonguerintln "Checking credit for " + name;
            creditCheckOk = false;
            if((income / 2) &gt; loanAmount){
               creditCheckOk = true;
            }
            outSmiley Tonguerintln "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>


<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;
  }
}

CreateApplicationTask


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);
   }
}

ProcessStartEvent.java


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);
   }
}



How can I read the value of the form LoanAmount?
2 REPLIES 2

habibhalaoui
Champ in-the-making
Champ in-the-making
Sorry the xml file

<code><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>
    outSmiley Tonguerintln "Checking credit for " + name;
    creditCheckOk = false;
    if((income / 2) &gt; loanAmount){
     creditCheckOk = true;
    }
    outSmiley Tonguerintln "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></code>

avc
Champ in-the-making
Champ in-the-making
the Var loanamount is case sensitive Smiley Wink you mean loanAmount in the getter