I'm using an ArrayList in a Minimum Binaray Heap Priority Queue. I'm kinda using it like a Vector. I'm declaring it new ArrayList() and implimenting this code:
I get a runtime error saying that I'm out of bounds... just from that snippet alone I didn't think I could go out of bounds.Code:int newNode = (_queue.size() + 1); _queue.ensureCapacity( newNode ); _queue.add(newNode, node);
The error says:
at java.util.ArrayList.add(ArrayList.java:367)
at MinBinaryHeapPriorityQueue.enqueue
(MinBinaryHeapPriorityQueue.java:82)
Line 82 is .add obviously, it says:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
Whats up with this? Is it something funny about ensureCapacity? I've never used it before. Sun's site doesn't say anything about take capacity -1 or anything... I've tried declaring the ArrayList( 100 ) no good. I've tried _queue.ensureCapacity( newNode + 1 ); and +2 and *2 still nothing.
Anything is a help as I'm on a tight deadline for this project. Thanks!
NOMAD




Reply With Quote