I was converting a bunch of ordinary for loops to for-each loops in my most recent project and ran into a paradoxical problem.
imgMap = new int[rows][cols];
for (int r=0; r<imgMap.length; r++) {
rowArray = mapBR.readLine().split(",");
for (int c=0; c<imgMap[r].length; c++) {
imgMap[r][c] = Integer.parseInt(rowArray[c]);
}
}
System.out.println(imgMap.length+", "+imgMap[0].length);
// print array in rectangular form
for (int[] r : imgMap) {
for (int[] c : imgMap[r]) {
System.out.print(" " + c[0]);
}
System.out.println("");
}
imgMap is a two-dimensional int array (int[][]) to hold a 'map'
mapBR is a BufferedReader of the external file that the 'map' is taken from
The first nested for loop set reads the file, the second nested for-each set writes it to the console to make sure that it is read correctly.
I couldn't see a way to make the first for loop set work as for-each loops so that is a sub-problem I would be delighted if someone could help me with as well.
Anyway, back to the main problem. when I (try to) compile this the compiler regurgitates an error saying that the int[] c : imgMap[r] line has incompatible types, but, and here's the catch, when I change it to int c : imgMap[r], it coughs up the same error! As I can't see how it could be any other than one of those types I am flummoxed.
I hope I have provided enough information.
IAmThePiGuy