我一直在尝试创建一个用于我们的 java 游戏的精灵。一切看起来都很正常,我在我的程序上没有看到任何错误,但是当它要运行时突然出现一个错误,它不能被实例化。有人可以告诉我它有什么问题吗?
@SuppressWarnings("unused")
public class TrueSprite
{
BufferedImage spriteSheet = ImageIO.read(new File("robin.png"));
int width = 240, height = 314, rows = 5 , columns = 5;
BufferedImage[] sprites = new BufferedImage[rows * columns];
public TrueSprite(int width, int height, int rows, int columns) throws IOException
{
this.width = width;
this.height = height;
this.rows = rows;
this.columns = columns;
for(int i = 0; i < rows; i++)
{
for(int j = 0; j < columns; j++)
{
sprites[(i * columns) + j ] = spriteSheet.getSubimage(i * width, j * height, width, height);
}
}
}
public void paint(Graphics g)
{
g.drawImage(sprites[1], 100, 100, null);
}
}
这是错误:
load: really.sprite.TrueSprite.class can't be instantiated.
java.lang.InstantiationException: really.sprite.TrueSprite
at java.lang.Class.newInstance(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)