anylogicagent-based-modeling

NullPointerException for List<T> variable in Anylogic


I am trying to model peer influence for churn situations. Agents will send messages to their peers depending on different conditions. I have also created a List called MessagesReceived to store received messages.(The number of these messages may be >1).

Variable declaration

Inside the Agent's Connections>Communications>OnMessageReceived , I have added this.Messages_Recieved.add(msg); which should add the received message to the list.

Now I get a NullPointerException Error on onReceive method of my agent.


Solution

  • first, you have a collections object in the agents palette that you can use instead of this, you can check the collection class options to select LinkedList

    enter image description here

    but if you insist in using a variable to define the list, you need to initialize it like this::

    linkedlist