This site requires JavaScript, please enable it in your browser!
Greenfoot back
fejfo
fejfo wrote ...

2016/3/31

weird exception

fejfo fejfo

2016/3/31

#
EDIT : I just found my mistake when checking for spelling mistakes but I don't know how to remove a post (it was that i'm using i++ in the second for loop if your wondering) when I run the following code I get this error message : java.lang.ArrayIndexOutOfBoundsException: -2147483648 at Room.generateLevel(Room.java:132) with this printed in the console : i:-2147483648 enemies:2
Double[][] poses  = new Double[enemies][2]; //x and y        
        for(int i = 0; i < enemies; i++) {
            //chose a pos
            int tries = 0;
            while(tries < 50) {
                double x = Math.random()/2+0.25;
                double y = Math.random()/2+0.1;
                tries++;

                //check if the pos is valid
                for(int i2 = 0; i2 < i; i++) {
                    if(distance(x,y,poses[i2][0],poses[i2][1]) < 0.1) {
                        continue;
                    }
                }
                
                try {
                    poses[i][0] = x;
                    poses[i][1] = y;
                }catch(ArrayIndexOutOfBoundsException ex) {
                    ex.printStackTrace();
                    System.out.println("i:"+i);
                    System.out.println("enemies:"+enemies);
                }
                break;
            }

            //add the enemie       
}
I have no idea how i can be negative if enemies == 2 it should always be lower then 2 right ?
You need to login to post a reply.