String [] secretCode = null;
String [] colores= {"Azul", "Amarillo", "Verde", "Naranja", "Rojo", "Rosa", "Blanco", "Gris"};
secretCode = new String[5];
//the array of random colors has to contain 5 colors only.
Random random = new Random();
for (int i = 0; i < secretCode.length; i++) {
int randomIndex = random.nextInt(colores.length);
secretCode[i] = colores[randomIndex];
System.out.println(secretCode);
//when i run this code it repeats the error 5 times.