13 Replies Latest reply on Dec 11, 2008 7:21 PM by 807589

    Need help on implementation of a circular queue with fixed size

      The constructor of the queue is as below:
      RingBufferNode[] element;
      RingBufferNode firstFree;
      RingBufferNode firstFilled;
      public RingBufferQueue (int n) {
                element = new RingBufferNode[n];
                for(int i=0; i<element.length-1; i++){
                     element.next = element[i+1];
                element[element.length-2].next = element[element.length-1];
                element[element.length-1].next = element[0];
                firstFree = element[0];
                firstFilled = firstFree;
           }class RingBufferNode {
           public Object value;
           public RingBufferNode next;

           public RingBufferNode (RingBufferNode n)
                { next = n; }
      Each node in the queue are expected to have a pointer "next" pointing to the next node in the queue, where the last one will be pointing to the first. When I called the constructor to create a new RingBufferQueue, the following error occurs:
      Exception in thread "main" java.lang.NullPointerException
      I've tried to throw the exception however it seemed to be a useless move.
      Edited by: ewrhgqerh on Dec 11, 2008 5:31 PM