I am running a java program through an application called Anylogic. I am creating a library that stores node objects for a water distribution system. I have provided the code for the two classes below. I am testing this code to see if I can access the nodes and initialize them properly. Any pointers on what is wrong with the code will help me out quite a bit.
/**
* NodeObject
*/
public class NodeObject implements java.io.Serializable {
private String nodeID;
private boolean gate;
private boolean securityCamera;
private boolean isExposed;
private String nodeType;
/**
* Default constructor
*/
public NodeObject(){
}
public void NodeObject(String nodeID, boolean gate, boolean securityCamera, boolean isExposed, String nodeType){
this.nodeID = nodeID;
this.gate = gate;
this.securityCamera = securityCamera;
this.isExposed = isExposed;
this.nodeType = nodeType;
return;
}
//--------------------------------------------------------------------------------------------------------------
public void alternateConstruct(String ID, boolean gateInfo, boolean securityCameraInfo, boolean exposureInfo, String nodeTypeInfo) {
this.nodeID = ID;
this.gate = gateInfo;
this.securityCamera = securityCameraInfo;
this.isExposed = exposureInfo;
this.nodeType = nodeTypeInfo;
return;
}
public String getNodeID() {
String returnval = this.nodeID;
return returnval;
}
public boolean hasGate() {
boolean returnval = this.gate;
return returnval;
}
public boolean hasSecurityCamera() {
boolean returnval = this.securityCamera;
return returnval;
}
public boolean exposed() {
boolean returnval = this.isExposed;
return returnval;
}
public String getNodeType() {
String returnval = this.nodeType;
return returnval;
}
@Override
public String toString() {
return super.toString();
}
/**
* This number is here for model snapshot storing purpose<br>
* It needs to be changed when this class gets changed
*/
private static final long serialVersionUID = 1L;
}
/**
* NodeLibrary
*/
public class NodeLibrary implements java.io.Serializable {
private String libraryName;
public NodeObject [] nodeArray = new NodeObject[10];
/**
* Default constructor
*/
public NodeLibrary(){
}
//--------------------------------------------------------------------------
public void initiateNodes() {
for(int i = 0; i < nodeArray.length; i++) {
nodeArray[i].alternateConstruct("J16", true, true, true, "Junction");
}
return;
}
public String getLibraryName() {
String returnval = this.libraryName;
return returnval;
}
public String getNodeID2(int indexValue) {
String returnval = nodeArray[indexValue].getNodeID();
return returnval;
}
public boolean hasGate2(int indexValue) {
boolean returnval = nodeArray[indexValue].hasGate();
return returnval;
}
public boolean hasSecurityCamera2(int indexValue) {
boolean returnval = nodeArray[indexValue].hasSecurityCamera();
return returnval;
}
public boolean isExposed2(int indexValue) {
boolean returnval = nodeArray[indexValue].exposed();
return returnval;
}
public String getNodeType2(int indexValue) {
String returnval = nodeArray[indexValue].getNodeType();
return returnval;
}
@Override
public String toString() {
return super.toString();
}
/**
* This number is here for model snapshot storing purpose<br>
* It needs to be changed when this class gets changed
*/
private static final long serialVersionUID = 1L;
}
This code is executed in the Anylogic application
NodeLibrary Dtown = new NodeLibrary();
Dtown.initiateNodes();
This is the error message that I get
NullPointerException
java.lang.NullPointerException
at epanet.NodeLibrary.initiateNodes(NodeLibrary.java:72)
at epanet.WDS.enterState(WDS.java:765)
at epanet.WDS.executeActionOf(WDS.java:675)
at com.xj.anylogic.engine.Statechart.start(Unknown Source)
at epanet.WDS.start(WDS.java:1886)
at epanet.Main.start(Main.java:2484)
at com.xj.anylogic.engine.Engine.start(Unknown Source)
at com.xj.anylogic.engine.ExperimentSimulation.b(Unknown Source)
at com.xj.anylogic.engine.ExperimentSimulation.run(Unknown Source)
at epanet.Simulation.executeShapeControlAction(Simulation.java:85)