Results 1 to 2 of 2
Thread: Creating and Array from an Array
- 01-02-2012, 04:34 PM #1
Member
- Join Date
- Jan 2012
- Posts
- 8
- Rep Power
- 0
Creating and Array from an Array
Hi, im trying to create a new array from and existing one i have but without the duplicates, then i can use this new array to populate a dropdown menu.
My problem is this, when i run the program i come across ""Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 33"" and i dont know how to get around it.
I've included the problem area (i think) below, and the full netbeanz file is here MEGAUPLOAD - The leading online storage and file delivery service.
Any help would be greatly appretiated
Java Code:public Arrays() { // Finds amount of different Route Codes (a) int a = 0; for (int i = 0; i < routecode.length; i++) { if (routecode[i].equals(routecode[i + 1])) { System.out.println("Entered if"); } else { System.out.println("Entered else"); a++; System.out.println(a); } } //Puts route codes into a new string without duplicates String[] menu = new String[a]; for (int i = 0; i < routecode.length; i++) { if (routecode[i].equals(routecode[i + 1])) { System.out.println("if"); } else { System.out.println("else"); menu[i] = routecode[i]; System.out.println(menu[i]); } } }
- 01-02-2012, 05:02 PM #2
Re: Creating and Array from an Array
Remember that the indexes for arrays go from 0 to the length-1. An index >= the length of the array is Out Of Bounds.Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 33
Look at the statement with the error and see what index used in that statement is past the end of the array.
If you can not tell, add printlns to print out ALL of the indexes values used on the line so you can see which one is out of bounds.
The index values are what is inside of the []s
Similar Threads
-
Creating an Array of Objects
By int80 in forum New To JavaReplies: 4Last Post: 08-09-2011, 12:40 PM -
Need help creating a String/Array?
By hla40 in forum New To JavaReplies: 2Last Post: 06-09-2011, 05:03 AM -
Creating Array of Objects
By chathurajeewaka in forum New To JavaReplies: 4Last Post: 12-03-2009, 03:23 PM -
Creating an array of objects
By geowizard in forum New To JavaReplies: 5Last Post: 11-16-2009, 01:25 AM -
creating array at runtime
By javaplus in forum New To JavaReplies: 4Last Post: 11-08-2007, 10:06 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks