I am having problems with this method.
It is a constructor with 2 parameters: a name and a String with 100 char called in. in must be turned in to a array[10][10] with vak(an object) in it.
I always get the same exception:
StringIndexOutOfBoundsException: String index out of range: 100
This is the method:
public SpelBord(String naam, String in) {
int muur=1;
this.naam = naam;
System.out.println(in.length());
for(int i=0;i<in.length();i++) {
for (int j = 0; j < vakken.length; j++) {
for (int k = 0; k < vakken[j].length; k++) {
if (in.charAt(i) == '.') {
this.vakken[j][k] = new Vak();
}
if (in.charAt(i) == 'K') {
this.vakken[j][k] = new Vak(false, false, new Kist());
}
if (in.charAt(i) == 'D') {
this.vakken[j][k] = new Vak(true, false);
}
if (in.charAt(i) == 'M') {
this.vakken[j][k] = new Vak(false, false, new Man());
}
if (in.charAt(i) == '#') {
this.vakken[j][k] = new Vak(false, true);
}
}
}
}
I think it is something with the for loops. thank you in advance!
iin eachifstatement ?iin each if-block?new Vak[10][10]vakken? and why is` irequired to in incremented in eachif` statement?