Search code examples
simulationanylogic

AnyLogic - inheritance of properties in batch block


I want to store process times in my model for each agent of type Box. For this purpose I have created a Java class ProcessData. My problem is that I always get NullPointerExceptions. I don't know if it's because of my code or the functionality of the batch block.

enter image description here

When the wait block reaches a certain size, all agents of type Box are routed to the batch block. The batch agent then waits in the seize block for staff member. If the agent is then seized, each agent of type Box contained in the batch agent should then get a start processing time. This is my code at enter of the delay block: box.getProcessData().add(new ProcessData(date(), duration()));. Using a constructor, I add the start time and duration as new variables to a new ProcessData entry.

To determine the end time of each Box agent I have the following code at unbatch block entry: box.getProcessData().getLast().setEnd(date());

Since I have a NullPointerException I can't tell exactly where it came from. My guess is that I have a bug with addressing the code: should I use agent. (from batch) or box. (name of original agent before batch)? Or is it not possible to give the batch agent properties that are inherited by the box agent?

First error is at unbatch, so the second code from above and second error is the following public void onExit( Box batch, Box agent ) { _unbatch_onExit_xjal( this, batch, agent ); }.

Following the screenshot of my error: enter image description here


Solution

  • The problem you have with this model first,is that you are seizing a resource for the batch without releasing that resource... you need to release before unbatch

    your error nevertheless is related to some code that you wrote in the on exit action of the unbatch block that you are unfortunately not telling us

    But to discover what is null, check with a traceln() the value of the variables that are present in the on exit section of the unbatch in order to print on the screen what is null