Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Mystery 'Array Index Out Of Bounds' Error

807588Mar 15 2009 — edited Mar 16 2009
I'm working on a linked list bit of code, with the following test method:
public class HeapTest {

	public static void main(String[] args) 
	{
		Heap MainHeap = new Heap();
		int Value, i;
		int Array[] = {100, 36, 19, 1, 25, 3, 17, 7, 2};
		
		for (i = 0; i < 10; i++)
		{
			Value = Array;
MainHeap.insert(Value);
}

Heap.printstart();
}

}
The list bits aren't the problem, as they've already been tested. When I ran the code making it randomize 10 variables for Value and inserting them, it worked fine. However, when I created the Array and changed it to cycle through the values and insert them, it gives me an 'Array Index Out Of Bounds' exception, but only when it assigns an Array entry to Value. When I tested it to print with the same For Loop, it works fine.

Can anybody see what's wrong here?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 13 2009
Added on Mar 15 2009
7 comments
181 views