我对java有点陌生,所以请把答案当成四岁的样子。=-D
我在这段代码中使用了 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;
}
}
感谢您的帮助甚至寻找。