Part of a java assignment I have requires me to use a set method to input details into an array. So far I have the following method to set the details
public void setCanopy(String uniqueRef, String modelName, int width, int height, int depth, int crewToBuild, double timeToBuild, double trailerLength, String available)
{
this.uniqueRef = uniqueRef;
this.modelName = modelName;
this.width = width;
this.height = height;
this.depth = depth;
this.timeToBuild = timeToBuild;
this.available = available;
this.crewToBuild = crewToBuild;
this.trailerLength = trailerLength;
}
This method works fine as long as it's only used to input details to a constructor, but when I try to use it with an array I get a NullPointerException.
I also have to display these details later on using get methods. I'm using the following method to display these but again, it only works if I'm using constructors.
public static void displayCanopyDetails(Canopy c)
{
System.out.println("Canopy reference number: " + c.getUniqueRef() + "\nCanopy model name: " + c.getModelName() +
"\nCanopy Dimensions (cm) - Width: " + c.getWidth() + " Height: " + c.getHeight() + " Depth: " + c.getDepth() +
"\nCrew to build: " + c.getCrewToBuild() + "\nTime to build canopy (minutes): " + c.getTimeToBuild() +
"\nTrailer Length: " + c.getTrailerLength() + "\nAvailability: " + c.getAvailable());
}
Any help getting these working with arrays would be greatly appreciated. Thanks.
In my main method I have
tentDetails(c[0]);
which calls the method
public static void tentDetails(Canopy c1,)
{
c1.setCanopy("CAN123", "Model1", 500, 200, 500, 5, 15, 10, "Available");
}
The NullPointerException error happens when it tries to run this method.