Home > Software engineering >  Anylogic: How to fix NullPointerException error within function?
Anylogic: How to fix NullPointerException error within function?

Time:01-01

I get a NullPointerException error in this scentence in my Anylogic model:

if (directRoute.routeCosts.get("Day") < toHubRoute.routeCosts.get("Night") fromHubRoute.routeCosts.get("Day")) {

This scentence is located within this function where the cheapest route should be found (to drive directly or via hub located in Region102), for every order that has to go from a certain terminal to certain customer.

enter image description here

The function is referring to the routes and costs of the following list:

enter image description here

The data sets for routes and costs are:

![enter image description hereenter image description here

Does anybody know why I get this error and how to fix it?

Thank you!

CodePudding user response:

It means that at that point of simulation either directRoute.routeCosts.get("Day") or toHubRoute.routeCosts.get("Night") or fromHubRoute.routeCosts.get("Day") does not exist.

It might potentially happen due to the following reasons:

  • Route does not exist at all
  • Having a look at your first screenshot, you check connections from "Region102". Are you doing that deliberately?
  • Having a look at your second screenshot, you say where (cost.route.eq(route.id)), is route.id column defined or given as input?

PS. The issue was that in the second screenshot, it should be costRow.get, not row.get.

  • Related