I’ve got this code
public String[][] checkBoxes(String[][] varden){
ArrayList[][] tillatnaSiffror = new ArrayList[9][9];
for(int i=0;i<9;i++){
for(int ruta=0;ruta<9;ruta++){
if(tillatnaSiffror[i][ruta] == null){
tillatnaSiffror[i][ruta] = new ArrayList<Integer>();
for(int add=1;add<=9;add++){
tillatnaSiffror[i][ruta].add(add);
}
}
if(varden[i][ruta].equals("X")){
for(int a=0;a<9;a++){
try {
System.out.println(tillatnaSiffror[i][ruta].indexOf(Integer.parseInt(varden[i][ruta])));
System.out.print("Testing");
} catch(Throwable n){
System.out.print("Throws exception");
}
}
}
}
}
}
tillatnaSiffror[i][ruta] is an ArrayList containing the numbers 1-9, and the variables i and ruta are from for loops that wrap around my code. The two-dimensional array varden contains strings with digits 1 to 9. The problem is, instead of printing the index I’m looking for, it does nothing. And it doesn’t print “Testing” afterwards either, and it’s not catched because of an exception either. I counted the amount of exceptions.
However, if I put in zero’s like this:
System.out.println(tillatnaSiffror[0][0].indexOf(Integer.parseInt(varden[0][0])));
Then it prints out the index, and also the “Testing” text. Any ideas why it doesn’t work with the variables? It’s not an ArrayIndexOutOfBounds problem; the variables are correct.
Without the whole code and without knowing what exception is thrown, my only suggestion is to split that line into multiple statements and see where it pops. Then you’ll probably be able to find the answer yourself.
Edit:
and then inside that
if:Do you see the problem?
BTW, you don’t seem to use
aof the thirdforanywhere, is that right?