我正在制作游戏,但是当我尝试启动它时,它说:java.lang.NullPointerException
.
这是代码:
package com.shinxs.rain.graphics;
import java.awt.Graphics;
import java.awt.Image;
import java.util.Random;
import javax.swing.ImageIcon;
public class Screen {
private int width, height;
public int[] pixels;
Graphics g;
public int[] tiles = new int[64 * 64];
private Random random = new Random();
ImageIcon i = new ImageIcon("Resources/Inventory.png");
Image image = i.getImage();
public Screen(int width, int height) {
this.width = width;
this.height = height;
pixels = new int[width * height];
for (int i = 0; i < 64 * 64; i++) {
tiles[i] = random.nextInt(0xFFFFFF);
}
}
public void clear() {
for (int i = 0; i < pixels.length; i++) {
pixels[i] = 0;
}
}
public void render() {
g.drawImage(image, 500, 200, 124, 280, null);
}
}
如果您知道如何解决它,请告诉我,我已经坚持了很长时间。