Phil Mendelsohn wrote:

> Hi,
>
> I'm picking up some Java on the fly, and am making what is probably a
> simple oversight type of error.  Could someone tell me why I'm having
> trouble accessing arrays of objects in an object from a class's member
> functions?
>
> Here is the beginning of the class, with the constructors.  It's a
> little messy -- there's been some initialization code added for
> debugging.  The constructor seems to work fine, but though it
> compiles, when I call it in another program (some test code) it just
> hangs as soon as it tries to read or write values in the arrays.
>
> I've been liberal with the 'public' statements; the reason (debugging
> / desperation!) should be clear, and is not an issue for what I'm
> doing.  This is a U homework thing, but it's not a Java class (it's
> Algorithms), so no fear about academic integrity in answering.
>
> Help is appreciated!
>
> Phil Mendelsohn
>
> --
> www.rephil.org
>
> "Trying to do something with your life is like
> sitting down to eat a moose." --Douglas Wood
>
> -----------
>
> public class PriorityQueue{
>
>     public qItem [] Q;
>     public int qSize;
>     public int [] where;
>
>     public class qItem{
>         public int item;
>         public int key;
>
>         public qItem(int item, int key){
>             //consructor
>             this.item = item;
>             this.key = key;
>         }
>     }
>
>     public PriorityQueue(int maxItem){
>         //constructor of an empty queue: see below
>         qItem [] Q = new qItem[maxItem];
>         int [] where = new int[maxItem];
>         for( int j=0; j < maxItem; j++){
>             where[j] = -1;
>             Q[j] = new qItem(-2, -3);
>             System.out.println(where[j] + " " + Q[j].item +
>                                " " +  Q[j].key);
>         }
>         int qSize = 0;
>     }//end constructor
>
>     void insert(int item, int key){
>         //insert the item with given key as its priority
>         qSize++;
>         System.out.println("qSize:  " + qSize);
>         System.out.println("Item: " + item);
>         System.out.println("Key: " + key);
>         for(int i = 0; i < qSize; i++){
>             System.out.println(Q[i].item);
>             System.out.println(Q[i].key);
>         }
>     }

By the way, you are missing a '}' at the end.  A couple of questions,
first is: aItem a inner class?  Second, do you have a main method that you
use for testing?  The reason I ask is I am not quite sure what the class
is supposed to do and a main/test method would help me walk through the
processing.

--
Perry Hoekstra
E-Commerce Architect
Talent Software Services
perry.hoekstra at talentemail.com