Код: Выделить всё
package tile;
import java.awt.Graphics2D;
import java.io.IOException;
import javax.imageio.ImageIO;
import main.gamePanel;
public class TileManager {
gamePanel gp;
Tile[] tile;
public TileManager(gamePanel gp) {
this.gp = gp;
tile = new Tile[10];
}
public void getTileImage() {
try {
tile[0] = new Tile();
tile[0].image = ImageIO.read(
getClass().getResourceAsStream("/tiles/grass.png")
);
tile[1] = new Tile();
tile[1].image = ImageIO.read(
getClass().getResourceAsStream("/tiles/wall.png")
);
tile[2] = new Tile();
tile[2].image = ImageIO.read(
getClass().getResourceAsStream("/tiles/water.png")
);
} catch (IOException e) {
e.printStackTrace();
}
}
public void draw(Graphics2D g2) {
g2.drawImage(tile[0].image, 48, 48, gp.tileSize, gp.tileSize, null);
}
}
Код: Выделить всё
public void update() {
player.update();
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
tileManager.draw(g2);
player.draw(g2);
g2.dispose();
}
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot read field image because "this.tile[0] is null
< /code>
Я позаботился о том, чтобы все переменные работали, и все файлы были одинаковыми. Пожалуйста, помогите ...
Подробнее здесь: https://stackoverflow.com/questions/797 ... lang-nullp
Мобильная версия