ola galera
eu tenho quatro pedaços de codigo igual ao de baixo, sendo que correspondem a quatro listasfinal List<Card> hand2 = new ArrayList<Card>();
for (int i = 0; i < 5; i++) {
hand2.add(gr.pickRandomCard());
}
// PLAYER2
ActionListener two = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (gr1.getCounter2() < 5) {
gr1.setCounter2(gr1.getCounter2() + 1);
for (int i = 0; i < arraybtn.length; i++) {
if (arraybtn[i] == e.getSource()) {
test3.setIcon(hand2.get(i - 10).getImage());
pn3.setText(Integer.toString(hand2.get(i - 10)
.toInt()));
pn7.setText(hand2.get(i - 10).toString());
pn70.setText(hand2.get(i - 10).suit());
gr1.validCard(hand, hand2, i, pn70);
}
}
} else {
pn7.setText("No more cards");
}
}
};
for (int i = 10; i < 15; i++) {
arraybtn[i].addActionListener(two);
arraybtn[i].setPreferredSize(new Dimension(120, 20));
arraybtn[i].setText(hand2.get(i - 10).toString());
contentor3.add(arraybtn[i], gbc);
}
eu estou verificando aqui, se ha valores comuns nas listas (para assistir se não o fez)
class FirstGame extends GameRules {
@Override
public boolean validCard(List<Card> hand, List<Card> hand2, int i, JTextField pn70, JTextField pn50) {
if(pn70.getText().equals (pn50.getText())) {
return true;
}
else {
for (Card c : hand2) {
if (c.suit().equals (hand.get(i).suit())) //erro aqui
return false;
}
}
return true;
}
@Override
public String winer(List<Card> hand, List<Card> hand2, int i,JTextField pn70, JTextField pn50) {
if (validCard(hand, hand2, i, pn70, pn50) == false) {
System.out.println("boa");
}
else
System.out.println("nao tao boa");
return null;
}
e estou recebendo o erro
Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: Index: 12, Size: 5
at java.util.ArrayList.rangeCheck(ArrayList.java:571)
at java.util.ArrayList.get(ArrayList.java:349)
at game.FirstGame.validCard(FirstGame.java:13)
at game.King$4.actionPerformed(King.java:373)
alguem pode ajudar? eu não sei porque ele esta dando o erro no array