ERROR while trying to run my java game -


The code below has been received in the console when trying to download the code to my code.

  Exceptions to the thread "main" java.lang.ArrayIndexOutOfBoundsException: 64 com.comli.blah.rainofwrath.graphics.Screen. & Lt; Init & gt; (Screen.java 22) at com.comli.blah.rainofwrath. Com comli.blah.rainofwrath.game.main (game.java:123) at & lt; Init & gt; (Game.java38)  

code:

  public class screen {Private int width, height; Public int [] pixel; Public final integer MAP_SIZE = 64; Public final integer MAP_SIZE_MASK = MAP_SIZE - 1; Public int [] tiles = new int [8 * 8]; Private random random = new random (); Public screen (integer width, integer height) {this.width = width; This.height = Height; Pixel = new int [width * height]; // 50,400 for (int i = 0; i & lt; MAP_SIZE * MAP_SIZE; i ++) {tiles [i] = random.nextInt (0xffffff); }} Public zero clear () (for (int i = 0; i & lt; pixel.lamp; i ++) {pixels [i] = 0;}} public zero render (int xoffset, int yOffset) {for (Int y = 0; y & lt; height; y ++) {int yy = y + y offset; // if (yy & lt; 0; yy & gt; = height) break; (int x = 0; {Int xx = x + xOffset; // if (xx; lt; 0x; x = width = break) for x & lt; width; x ++; int tile index = ((xx> 4 ) And MAP_SISSMSMM + + ((YY> 4) and MAP_SISSMM) * MAP_SCAJ; pixels [x + y * width] = Sprite. Grass pixels [(A S and 15) + (Y and 15) * Sprite. GRCE. SCEE]}}}}}  

Here the problem is in the tiles array has 64 (8 * 8) elements during its initial startup, while specifying i & lt; MAP_SIZE * MAP_SIZE ( MAP_SIZE = 64 ), you are trying to go beyond this limit on the stop-rule . I believe it should be:

  public int [] tiles = new entry [MAP_SIZE * MAP_SIZE]  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

lua - HowTo create a fuel bar -