import java.util.Random;
import java.util.ArrayList;
public class Game {
ArrayList<Integer> numere = new ArrayList<>();
ArrayList<Bila> balls = new ArrayList<Bila>();
ArrayList<String> culori = new ArrayList<>();
Random random = new Random();
int nrBalls=0;
public void createColours(){
for(int i=0;i<7;i++){
culori.add("Portocaliu");
culori.add("Rosu");
culori.add("Albastru");
culori.add("Verde");
culori.add("Negru");
culori.add("Galben");
culori.add("Violet");
}
}
public void createNumbers(){
for(int i=1;i<50;i++){
numere.add(i);
System.out.print(numere.size());
}
}
public void createBalls(){
while(nrBalls<36){
int nr =numere.get(random.nextInt(numere.size()));
numere.remove(nr);
String culoare =culori.get(random.nextInt(culori.size()-1));
culori.remove(culoare);
balls.add(new Bila(culoare,nr));
nrBalls++;
}
}
}
So i have another class with main method and in that class i call createNumbers() ,createColours(),createBalls().when i run the program i get an IndexOutOfBoundsException at numere.remove(nr) saying index:a number and size:another number ..always the second number is smaller than the first number..Why is this happening ?where am I wrong?