0

I am not sure what the issue is when I enter a box for the first choice a it returns

2 Answers2

0

Because you have not initialize box[0]. You only allocated the space of the array.

You should do something like:

box[0] = new PO();

Remember that 'new' the array doesn't mean you 'new' the object. The array you use is to store the references(pointers) of objects.

Also, to improve the evolvability, please use a dynamic array such as ArrayList. Since the size of array is fixed once you create it.

Euclid Ye
  • 501
  • 5
  • 13
0
PO[] box = new PO[nBoxes];

This line here is creating an array of references of class-type PO. You need to allocate memory or create an instance using new. For each reference in the array you must do this else the references point to null. for(int i=0;i < nBoxes;i++) { box[i] = new PO(); }