Hye everyone,
I am trying to make a 2d-char array, fill it with random letters(chars) and print it. If I do it like this I get a ArrayIndexOutOfBoundsException: 0. I am a newbee.
I import my prefs(width, height) from static getters in the class preferences.
Can anyone help me please?
thanx.
stroper
class Playgame {
private final List<Integer> lengte = new ArrayList<Integer>();
private int width;
private int height;
private Random random = new Random();
private static char[] alfabet = { 'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z' };
public char[][] bogglefield = new char[height][width];
public void copyPreferences() {
width = preferences.getWidth();
height = preferences.getHeight();
}
public void fieldInit(){
for(int i = 0; i < bogglefield.length;i++){
for(int j = 0; j < bogglefield.length; j++){
bogglefield[i][j] = alfabet[random.nextInt(26)];
}
}
}
public void fieldPrint(){
for (int i =0; i < height; i++) {
for (int j = 0; j < width; j++) {
System.out.print(" " + bogglefield[i][j]);
}
System.out.println("");
}
}
void start() {
copyPreferences()
fieldInit();
fieldPrint();
}