-1
我想優化我使用教程構建的Animation類,但每當我嘗試將BufferedImage添加到類型爲BufferedImage的LinkedList時,我都會得到一個NullPointerException。BufferedImage LinkedList
這是我的代碼:
public class Animation
{
private int speed;
private int frames;
private int index = 0;
private int count = 0;
private LinkedList<BufferedImage> img;
private BufferedImage currentImg;
public Animation(int speed, BufferedImage img1, BufferedImage img2)
{
this.speed = speed;
img.add(img1);
img.add(img2);
}
}
爲什麼我不能在BufferedImage中添加到LinkedList的?
你在哪裏初始化'img'?在向這個LinkedList添加元素之前,你應該這樣做......你如何調用這個構造函數? – vefthym 2014-11-08 09:37:00
我試過 anim = new動畫( 2, game.getBufferedImage(0,0), game.getBufferedImage(0,1)) – 2014-11-08 09:40:21