0
votes

I have been trying to fix a NullPointerException for awhile now and I am completely stumped. It is occurring in a 'seize' block, but I cannot determine what exactly is causing it.

I have a feeling it could be the code I have inputted into the seize block due to the fact that I am a beginner.

I am trying to seize another agent and send it to different parts of the world via a parameter within the 'order' agent that contains a value from 1 to 8.

On seize unit I have the following code:

if (agent.missionLocation <= 1); KC30resource1.moveTo(main.AsiaRegion.randomPointInside());
{
if (agent.missionLocation <= 2); KC30resource1.moveTo(main.AfricaRegion.randomPointInside());
}
{
if (agent.missionLocation <= 3); KC30resource1.moveTo(main.MiddleeastRegion.randomPointInside());
}
{
if (agent.missionLocation <= 4); KC30resource1.moveTo(main.EuropeRegion.randomPointInside());
}
{
if (agent.missionLocation <= 5); KC30resource1.moveTo(main.NAmericaRegion.randomPointInside());
}
{
if (agent.missionLocation <= 6); KC30resource1.moveTo(main.SAmericaRegion.randomPointInside());
}
{
if (agent.missionLocation <= 7); KC30resource3.moveTo(main.AustraliaNzRegion.randomPointInside());
}
{
if (agent.missionLocation <= 8); KC30resource2.moveTo(main.PacificRegion.randomPointInside());
}

Could this be the reason why it is happening?

Exception during discrete event execution:

NullPointerException

java.lang.NullPointerException

    at com.anylogic.libraries.processmodeling.Seize.a(Unknown Source)

    at com.anylogic.libraries.processmodeling.Seize.a(Unknown Source)

    at com.anylogic.libraries.processmodeling.Seize.a(Unknown Source)

    at com.anylogic.libraries.processmodeling.Seize.a(Unknown Source)

    at com.anylogic.libraries.processmodeling.Seize.a(Unknown Source)

    at com.anylogic.libraries.processmodeling.Seize.a(Unknown Source)

    at com.anylogic.libraries.processmodeling.Seize.a(Unknown Source)

    at com.anylogic.libraries.processmodeling.Seize$16.a(Unknown Source)

    at com.anylogic.libraries.processmodeling.Seize$16.action(Unknown Source)

    at com.anylogic.libraries.processmodeling.AsynchronousExecutor_xjal.executeActionOf(Unknown Source)

    at com.anylogic.engine.EventTimeout.execute(Unknown Source)

    at com.anylogic.engine.Engine.f(Unknown Source)

    at com.anylogic.engine.Engine.gj(Unknown Source)

    at com.anylogic.engine.Engine.e(Unknown Source)

    at com.anylogic.engine.Engine$m.run(Unknown Source)

Expected results are that the unit will fly to the GISregion specified in the code. Each 'MoveTo' block for each region is connect to the Seize block.

Thank you in advance.

1

1 Answers

0
votes

I think you are using the Seize block wrong. You are trying to tell the resource to move within the seize object but that is not how you do this, see some tutorials on that.

Instead, you set up your resource pool with your resources (Seems to be KC30 in your case). Set it up to have 10 or however many you have.

Now in Seize, make your order seize 1 KC30 from the resource pool. You may tell it to first move towards the order agent, if you like: enter image description here

To make the KC30 agent move to a region with the order now, you use a "MoveTo" block after the seize block and tell the order (and its seized KC30) to your world region with your code.

PS: your if-statements could be replaced by a switch statement, it is more elegant and error-proof, check it out :-)