hi, im mexican and i have 19 years old, im tryng to make a game in java, but i have this error when i try to run display: Exception in thread "Thread-2" java.lang.ArrayIndexOutOfBoundsException: 400
at come.mine.minefront.graficos.Render.draw(Render.ja va:23)
at come.mine.minefront.graficos.Screen.render(Screen. java:20)
at come.mine.minefront.Display.render(Display.java:78 )
at come.mine.minefront.Display.run(Display.java:61)
at java.lang.Thread.run(Unknown Source)
400

this is my code

Class number one its called:

-------------
Display.java
-------------

package come.mine.minefront;

import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;

import javax.swing.JFrame;

import come.mine.minefront.graficos.Render;
import come.mine.minefront.graficos.Screen;

public class Display extends Canvas implements Runnable {

private static final long serialVersionUID = 1L;
public static final int WIDHT = 800;
public static final int HEIGHT = 400;
public static final String TITLE = "Craftlife";

private Thread thread;
private Screen screen;
private BufferedImage img;
private boolean running = false;
private Render render;
private int [] pixels;

public Display() {
screen = new Screen(WIDTH, HEIGHT);
img = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
pixels = ((DataBufferInt)img.getRaster().getDataBuffer()).g etData();
}

private void start() {
if (running)
return;
running = true;
thread = new Thread(this);
thread.start();

System.out.println("working");

}

private void stop() {
if (!running)
return;
running = false;
try {
thread.join();
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}

}

public void run() {
while (running) {
tick();
render();

}

}

private void tick() {

}

private void render() {
BufferStrategy bs = this.getBufferStrategy();
if (bs == null) {
createBufferStrategy (3);
return;
}

screen.render();

for (int i = 0; i<WIDTH*HEIGHT; i++) {
pixels [i] = screen.pixels[i];
}

Graphics g = bs.getDrawGraphics();
g.drawImage(img, 0, 0, WIDHT, HEIGHT, null);
g.dispose();
bs.show();
}

public static void main(String[] arg) {
Display game = new Display();
JFrame frame = new JFrame();
frame.add(game);
frame.setTitle(TITLE);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setSize(WIDHT, HEIGHT);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setVisible(true);

System.out.println("Running...");
game.start();
}
}

-------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------


Class number two its called:


--------------------------------
*Render.java (i dont know why is a * there, i dont put it there, in the packege explorer says only Render.java)
--------------------------------

package come.mine.minefront.graficos;

public class Render {
public final int width;
public final int height;
public final int[] pixels;

public Render (int width, int height) {
this.width = width;
this.height = height;
pixels = new int [height * width];

}

public void draw (Render render, int xOffset, int yOffset) {
for (int y = 0; y < render.height; y++) {
int yPix = y + yOffset;


for (int x = 0; x < render.width; x++) {
int xPix = x + xOffset;

pixels [xPix + yPix * width] = render.pixels [x + y * render.width];

}
}
}
}





------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------

And my 3rd class its called:

-------------------
Screen.java
-------------------


package come.mine.minefront.graficos;

import java.util.Random;

public class Screen extends Render {

private Render test;

public Screen(int width, int height) {
super(width, height);
Random random = new Random();
test = new Render(256, 256);
for (int i = 0; i <256*256; i++) {
test.pixels [i] = random.nextInt();

}
}

public void render() {
draw (test, 0, 0);
}

}


-------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------

The error apears when i try to run display, plase somebody helpme plase, plase, plase, im new in java, i started today