Hey,
I'm a bit new to java, so please bear with me. I have a class that contains 2 arraylists which i'm trying to store objects into, one for each object type. in my main class, i'm insert the objects like so:
for (int i =0; i < 3; i++)
{
Cat cat = new Cat("meow",i);
Dog dog = new Dog("woof",i);
objList.addCat(cat);
objList.addDog(dog);
}
my ObjectList (objList) class is setup like:
import java.util.ArrayList;
public class ObjectList {
public ArrayList cats;
public ArrayList dogs;
public ObjectList()
{
this.cats = new ArrayList();
this.dogs = new ArrayList();
}
public void addCat(Cat c)
{
this.cats.add(c);
}
public void addDog(Dog d)
{
this.dogs.add(d);
}
}
I get a java.lang.NullPointerException starting at the objList.addCat(cat); line however. I printed out the cat objects properties right before this line, and both values seem to be set. I tried to see if i could just pass an int to my addCat arrayList, but got the same error, so I assume I'm using arraylist within my class incorrectly. Is there an error in my code that's readily apparent?