When calling a method that adds an object to a collection in GWT I get a null pointer error. I have no idea why as everything I have done creates a very simple object (only contains a string). Here is the code that calls the function and the function:
public class PlantMenu extends VerticalPanel {
private Collection<PlantData> plantList;
private Collection<PlantData> newPlantData;
public PlantMenu() {
createPlants();
/*
for(Iterator<PlantData> i = plantList.iterator(); i.hasNext();) {
Window.alert(i.next().getPlantName());
}*/
}
public Collection<PlantData> createPlants() {
PlantData plant1 = new PlantData("Herbs");
PlantData plant2 = new PlantData("Flowers");
PlantData plant3 = new PlantData("Vegetable");
newPlantData.add(plant1);
newPlantData.add(plant2);
newPlantData.add(plant3);
return newPlantData;
}
}
It errors out (null pointer) when trying to add the first plant, this line:
PlantData plant1 = new PlantData("Herbs");
Any help appreciated :)