Results 1 to 4 of 4
Thread: Array index out of bounds error
- 12-28-2010, 02:37 AM #1
Member
- Join Date
- Dec 2010
- Posts
- 2
- Rep Power
- 0
Array index out of bounds error
i am trying to select an item in a JList and compare the index to the position in the vector. if they are equal then the element at that postion will be moved then the JList will display the new list without the selected element.
here is my code
int i = vehicleJList.getSelectedIndex();
System.out.println(i);
try{
String [] bLine = new String[carVector.size()];
int p = 0;
//BufferedReader readCar1 = new BufferedReader(new FileReader(carFile));
Scanner carScanner1 = new Scanner(carFile);
while(carScanner1.hasNextLine() == true && carScanner1.next() != null){
bLine[p] = carScanner1.nextLine();
while(p <= carVector.size() && (foundCar != true || foundVan != true)){
for (int o = 0; o < carVector.size(); o++){
System.out.println(carVector.get(o) + " " +carVector.get(i));
if(carVector.get(o).equals(carVector.get(i))){
carVector.removeElementAt(o);
foundCar = true;
break;
}
else{
System.out.println("not it");
}
}
for(int o = 0; o < vanVector.size(); o++){
System.out.println(p);
System.out.println(vanVector.get(o) + " " + vanVector.get(i));
if(vanVector.get(o).equals(vanVector.get(i))){
foundVan = true;
vanVector.removeElementAt(o);
break;
}
else{
System.out.println("not it");
}
}
}
if(foundCar = true){
vehicleJList.setListData(carVector);
}
if(foundVan = true){
vehicleJList.setListData(vanVector);
}
}
- 12-28-2010, 02:38 AM #2
Member
- Join Date
- Dec 2010
- Posts
- 2
- Rep Power
- 0
error code
here is the error i get
regnum2 VW Golf Manual 2008 Black HatchBack 3 5
regnnumm1 Vauxall Corsa Manual 2004 Blue HatchBack 5 5
1
regnum2 VW Golf Manual 2008 Black HatchBack 3 5 regnnumm1 Vauxall Corsa Manual 2004 Blue HatchBack 5 5
not it
regnnumm1 Vauxall Corsa Manual 2004 Blue HatchBack 5 5 regnnumm1 Vauxall Corsa Manual 2004 Blue HatchBack 5 5
java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 1
- 12-28-2010, 03:22 AM #3
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 11
- 12-28-2010, 03:37 AM #4
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 11
I think the problem might be a typo.
To avoid this problem (if you are using Eclipse) go to
Window → Preferences → Java → Compiler → Errors/Warnings → Potential programming problems
and set “Possible accidental boolean assignment (e.g. 'if (a = b)'):” to “Error”.
Java Code:if(foundCar = true){ vehicleJList.setListData(carVector); } if(foundVan = true){ vehicleJList.setListData(vanVector); }
'foundCar' and 'foundVan' with 'true' which gives the same effect as
Java Code:foundCar = true; vehicleJList.setListData(carVector); foundVan = true; vehicleJList.setListData(vanVector); }
Similar Threads
-
Help Array Index out of bounds exception
By star400040 in forum New To JavaReplies: 2Last Post: 12-10-2010, 11:24 PM -
Array Index Out Of Bounds Exception
By manowar689 in forum New To JavaReplies: 3Last Post: 06-19-2010, 12:25 AM -
array Index out of Bounds exception== 0
By Allgorythm in forum New To JavaReplies: 6Last Post: 02-11-2010, 05:02 PM -
Array Index Out of Bounds Exception
By kool001 in forum New To JavaReplies: 1Last Post: 12-03-2009, 08:42 AM -
Array Index out of bounds
By leapinlizard in forum New To JavaReplies: 5Last Post: 04-29-2009, 06:11 AM
Bookmarks