我正在尝试在类中创建一个内部类,然后将其初始化为第一个值= 0 我有这个。
class Vehicle {
internal class AGVSteps {
public double X { get; set; }
public double Y { get; set; }
}
private AGVSteps[] steps ;
public AGVSteps [] Steps {
get { return this.steps; }
}
public Vehicle() { //constructor
this.steps = new AGVSteps[2000];
this.steps[0].X = 0; //CRASHES HERE
MessageBox.Show(this.steps[0].X + "");
for (int i = 0; i < 2000; i++) {
// this.steps[i].X = -1;
//this.steps[i].Y = -1;
}
}
}
任何想法?我收到NPE错误。谢谢!
答案 0 :(得分:1)
steps
是AGVSteps
个对象的容器。您需要初始化AGVSteps
本身
this.steps = new AGVSteps[2000];
for (int i = 0; i < steps.Length; i++) {
steps[i] = new AGVSteps();
}