So, adding stuff to my custom linked list is causing a NullPointerException
, and I cannot, for the life of me, figure out why. The purpose of the program is to simulate a chest of drawers, with a list that has the drawers as nodes. The drawers each have a list that includes household objects as nodes.
Here's the relevant bits of code. The error happens when I create a: new ChestOfDrawers(3);
in my UI class:
public class ChestOfDrawers{
private static OwnList chest;
private static int[] parametres;
public ChestOfDrawers (int drawers){
chest = new OwnList();
create();
}
public static void create(){
for (int i = 0; i < parametres.length; i++) {
Object drawer = new Drawer(i, parametres[i]);
chest.add(i, drawer); //This is causing the error
}
}
}
The Drawer
class being referred to here is the class for the drawers. It requires int i
as an ID and int parametres
as drawer capacity. The parametres[]
array gets filled before the additions to the list are made and it includes info for drawer capacity. The linked list in the question (OwnList
) is functioning 100% correctly as it is part of a provided course material, it's near identical to Java's own. I tested the class in another test class and it worked fine, I've just made a mistake here somewhere. Please help!