Mam problem otóż wywala mi błąd Exception in thread "Thread-3" java.lang.NullPointerException, dokładnie w ostatnim ifie, kompletnie nie mam pojęcia czemu i ni mogę znaleźć odpowiedzi. Z góry dzięki za pomoc :)
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Map {
public int width;
public int height;
public Piece[][] piece;
public Map(String path) {
try {
BufferedImage map = ImageIO.read(getClass().getResource(path));
this.width = map.getWidth();
this.height = map.getHeight();
int[] pixels = new int[width * height]; // jedno wymiarowa tablica
map.getRGB(0, 0, width, height, pixels, 0, width);
// petla ma na celu przerobic
for (int xx = 0; xx < width; xx++) {
for (int yy = 0; yy < height; yy++) {
int val = pixels[xx + (yy * width)];
if (val == 0xFF000000) {
piece[xx][yy] = new Piece(xx * 32, yy * 32);
}
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
}
// petla, ktora
public void fireUp(Graphics g) {
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
if (piece[x][y] != null) piece[x][y].fireUp(g);
}
}
}
}