2017-03-14 1 views
0

클래스 내부 클래스를 만든 다음 첫 번째 값으로 초기화하려고합니다. = 0 저는 이것을 가지고 있습니다.내부 클래스 배열을 초기화 할 때 NPE

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 오류가 발생합니다. 감사합니다.

답변

1

stepsAGVSteps 개체의 컨테이너입니다. AGVSteps 자체를 초기화해야합니다.

this.steps = new AGVSteps[2000]; 
for (int i = 0; i < steps.Length; i++) { 
    steps[i] = new AGVSteps(); 
} 
+0

아, 고맙습니다. 내 마음이 죽은 것 같습니다. –

관련 문제