【发布时间】:2018-04-02 21:12:05
【问题描述】:
我正在创建一个正在处理的小游戏,我正在尝试打印一个 2D 方形对象数组。我有这个NullPointerException,但我似乎在网上找不到类似的东西。
int edge = 10;
public int sizeOfRect = 50;
public int numberOfRects = 10;
Rectangle[][] player = new Rectangle[numberOfRects][numberOfRects];
public int k;
public int l;
public int kcount=0;
public int lcount=0;
void setup(){
background(200);
size(565, 565);
}
void draw(){
for(k=edge; k<width-edge; k+=55){
for(l=edge; l<height-edge; l+=55){
player[kcount][lcount].display();
lcount++;
}
lcount=0;
kcount++;
}
kcount=0;
}
和矩形类
class Rectangle{
int i;
int j;
Rectangle(){
i=k;//xcoor
j=l;//ycoor
}
void display(){
fill(0);
rect(i,j,sizeOfRect,sizeOfRect);
}
}
最后是例外
Plain.pde:17:0:17:0: NullPointerException 完成。无法运行 草图(目标虚拟机初始化失败)。有关更多信息,请阅读 revisions.txt 和帮助?故障排除。无法运行草图。
提前谢谢你
【问题讨论】:
-
可能因为必须在
for循环中初始化二维数组player,见stackoverflow.com/questions/12231453/…
标签: processing