0

I am almost done with my assignment, however I'm trying to draw out a map, but my nested for loop seems to be causing trouble. The following is the code and error I'm getting

 public void draw(){
System.out.println("Starting Drawing Process");
System.out.println("Height is: " + height);
System.out.println("Width is: " + width);
for(int i = 0; i < (width -1); i++){
    for(int j = 0; i < (height -1) ; j++){
        map[i][j].draw(i, j);
        System.out.println(map[i][j] + "Has been printed");
    }
}
System.out.println("Drawing process has ended");

The error I get is

 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
at World.draw(World.java:70)
at World.main(World.java:89)

This coincides with the line map[i][j].draw(i,j);

The values for height and width is 10 & 5 respectively

Kevin
  • 47
  • 4
  • you should rather define the conditions as `i < map.length` and `j < map[i].length`. – SomeJavaGuy Mar 07 '16 at 16:28
  • Just to expand on the close: what applies to a one-dimensional array also applies to multi-dimensional arrays, it's just an array of arrays so the length needs to be checked on all arrays. – Thomas Mar 07 '16 at 16:30

1 Answers1

3
for(int j = 0; i < (height -1) ; j++){

there's a 'i' that should be a 'j'.

tomiy
  • 146
  • 5