【发布时间】:2013-01-12 15:55:24
【问题描述】:
您好,我正在为学校创建一个小游戏,但是当我尝试这样做以填写此数组中的 x 和 y 变量时,我得到了一个 NPE。 有人可以帮忙吗?
public class mainclass {
public static void main(String[] args) {
Gra piece[] = new Gra[10];
for (int i = 0; i < piece.length; i++) {
piece[i].x = 50;
piece[i].y = 50;
}
}
}
class Gra{
public int x = 50;
public int y = 10;
}
【问题讨论】:
-
向我们展示堆栈跟踪。你在哪条线上得到它?
标签: java arrays loops for-loop nullpointerexception