getting a frustrating null exception error when the class junction is being used in functions. The class should be initialised so this shouldn't be an issue. Help ;_;
class RobotData {
class Junction {
public int juncX;
public int juncY;
public int arrivalHeading;
}
private static int maxJunctions = 10000; //Max junctions likely to occur
private static int junctionCounter;
private static Junction[] junction;
RobotData() {
junctionCounter = 0;
junction = new Junction[maxJunctions];
}
public void resetJunctionCounter() { junctionCounter = 0; }
public void recordJunction(IRobot robot) {
junction[junctionCounter].juncX = robot.getLocation().x;
junction[junctionCounter].juncY = robot.getLocation().y;
junction[junctionCounter].arrivalHeading = robot.getHeading();
junctionCounter++;
}
public void printJunction() {
System.out.println(junction[junctionCounter].juncX);
System.out.println(junction[junctionCounter].juncY);
System.out.println(junction[junctionCounter].arrivalHeading);
}
}
The class RobotData is being initialised properly, but when the functions are being called I get the null error indicating that junction[junctionCounter] hasn't been initialised yet. Unsure why (obviously) as it should be initialised when RobotData is.