I am trying to create an array
of boats, containing RaceBoat
objects and SailBoat
objects. Currently I have this:
Boat[] boats;
totalBoatCount = args.length;
for (int i = 0 ; i < totalBoatCount ; i++)
{
char firstChar = boatNames[i].charAt(0);
if (Boat.isItRaceBoat(firstChar))
{
boats[i] = new RaceBoat(boatNames[i]);
}
else
{
boats[i] = new SailBoat(boatNames[i]);
}
}
every time I create a new SailBoat or RaceBoat, I get a java.lang.NullPointerException
. How am I supposed to phrase this to create this array?