Reputation: 47
In my Programm I want to delete all items from an array, where the hd is not between temp_unten and temp_oben, but the for-loop goes to -1 and gives me this fail (I marked the line with an '^'):
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
if (hd) {
int temp_unten = Integer.parseInt(spnHDUnten.getValue() + "");
int temp_oben = Integer.parseInt(spnHDOben.getValue() + "");
switch (cmbHDOben.getSelectedItem() + "") {
case "MB":
break;
case "GB":
temp_oben = temp_oben * 1000;
break;
case "TB":
temp_oben = temp_oben * 1000 * 1000;
break;
}
switch (cmbHDUnten.getSelectedItem() + "") {
case "MB":
break;
case "GB":
temp_unten = temp_unten * 1000;
break;
case "TB":
temp_unten = temp_unten * 1000 * 1000;
break;
}
if (!(temp_oben < temp_unten)) {
for (int i = zutreffendeObjektnummern.size() - 1; i >= 0; i--) {
for (int i2 = GUI.objekte_objekt_ID.size() - 1; i >= 0; i2--) {
^ if (!(GUI.hd.get(i2).replaceAll("[^0-9.,]+", "").equalsIgnoreCase("")) && Integer.parseInt(GUI.objekte_objekt_ID.get(i2).replaceAll("[^0-9.,]+", "")) == Integer.parseInt(zutreffendeObjektnummern.get(i).replaceAll("[^0-9.,]+", ""))) {
if (Integer.parseInt(GUI.hd.get(i2).replaceAll("[^0-9.,]+", "")) < temp_unten || Integer.parseInt(GUI.hd.get(i2).replaceAll("[^0-9.,]+", "")) > temp_oben) {
zutreffendeObjektnummern.remove(i);
}
}
}
}
} else {
JOptionPane.showMessageDialog(this, "Von/Bis muss beim Auswahlen von Spannen beachtet werden!", "Fehlerhafte Eingabe", JOptionPane.INFORMATION_MESSAGE);
}
}
Thank you for your help :)
Upvotes: 0
Views: 62
Reputation: 1106
Your inner for loop condition should use i2
instead of i
. It should look something like this:
for (int i2 = GUI.objekte_objekt_ID.size() - 1; i2 >= 0; i2--)
Upvotes: 1