我對java有點新,所以請將愚蠢的答案,如果我是四歲。 = -D空指針異常 - 將項目添加到ArrayList
我對此代碼使用slick。如果你需要更多的代碼,請問。我只想發佈我認爲相關的內容,但由於我是編程新手,可能是錯誤的。
我追蹤了問題的起因,將一個新創建的對象添加到arrayList中。 下面的代碼:
public ArrayList<Walls> walls;
Walls w1 = new Walls(new RPoint(100,100), brickwall, brickwall, 100);
walls.add(w1); //this is where the error will occur at.
牆壁類:
package main;
import org.newdawn.slick.Image;
import org.newdawn.slick.geom.Rectangle;
public class Walls {
private RPoint p;
private Image i;
private Image i2;
private int durability;
//private Rectangle r = new Rectangle (1,1,1,1);
public Walls(RPoint a, Image b, Image c, int d){
this.p=a;
this.i=b;
this.i2=c;
this.durability=d;
// Rectangle r = new Rectangle(Math.round(a.getX()), Math.round(a.getY()), Math.round(b.getWidth()), Math.round(b.getHeight()));
}
public Image getImage()
{
return this.i;
}
// public Rectangle getRect()
// {
// return this.r;
// }
public Image getSecondaryImage()
{
return this.i2;
}
public int getLife()
{
return this.durability;
}
public RPoint getPoint()
{
return this.p;
}
}
感謝任何幫助或連看。
public ArrayList walls = new ArrayList (); –
user1516873