I have a class Food which creates foods and starts a new thread. Amongst other things.
private Thread foodThread;
public void start() {
foodThread = new Thread(this, "Food");
foodThread.start();
}
The I have a board class which has an Arraylist buffet which uses the methods from Food.
ArrayList<Food> buffet;
for (int i=0; i<15; i++){
buffet.add(new Food(this));
}
Now what I want to do is start a new thread from the Food class so (foodThread) inside the for loop. I tried
public Food food;
and then
food.start();
inside the loop but that doesn't seem to work, it just throws an error.java.lang.NullPointerException