jeudi 22 janvier 2015

Tricky NullPointerException

For my Computer Science course, we're making a program that simulates a vending machine business. Everything seems not to have any errors, but then this line in the driver runs,



VendingMachine pv0001 = new SnackMachine(19.00);
pv0001.addItem(new Chips("Doritos"));


it returns this error



Exception in thread "main" java.lang.NullPointerException
at SnackMachine.addItem(SnackMachine.java:35)
at Driver.main(Driver.java:9)


Which is apparently stemming from the declaration of this if statement the SnackMachine code:



public boolean addItem(VendingMachineItem item)
{
if((item instanceof Snack) && (inventory.size() < maxCapacity))//error on this line
{
inventory.add(item);
return true;
}else{
return false;
}
}


I can't seem to figure out what the issue is, can anybody help me?


Aucun commentaire:

Enregistrer un commentaire