I am not sure what the issue is when I enter a box for the first choice a it returns
            Asked
            
        
        
            Active
            
        
            Viewed 37 times
        
    2 Answers
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(); }
 
    
    
        Prabhat Choudhary
        
- 169
- 1
- 13