Ok,
I am really new to java (and programming in general) so don't be too surprised when you see something strange.
Basically what I am trying to do is change the order of array elements because I want to "remove" one element from the array.
For example participant 2 gets knocked out, I want to remove him. I want the participant with the highest index to replace participant 2 and then reset the highest index participants values to default.
Fighter k1=participant[jList1.getSelectedIndex()];
Fighter k2=participant[jList2.getSelectedIndex()];
k1.fightsWith(k2);
if (k1.refresh()==true) {
if (k1.getHP()<=0) {
participant[k1.getID()]=participant[amount];
participant[k1.getID()].setID(k1.getID());
participant[amount].reset();
amount-=1;
} else if(k2.getHP()<=0){
participant[k2.getID()]=participant[amount];
participant[k2.getID()].setID(k2.getID());
participant[anzahl].reset();
amount-=1;
}
jList1Model.clear();
jList2Model.clear();
for (int i=0;i<amount;i++) {
if (participant[i].getID()<=20) {
jList1Model.addElement(participant[i].getName());
jList2Model.addElement(participant[i].getName());
}
}
}
The lines participant[k1.getID()]=participant[amount];
participant[amount].reset();
are giving me trouble here.
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException