2011-12-08 7 views
0

나는이 객체를 "this"가 Point의 배열이되게하려는 programm에 대해 작업하고 있지만 programm를 실행할 때이 오류가 발생하며 그 이유를 이해할 수 없습니다. 오류 -> DouglasPeucker. 내 programm에 :배열 점의 생성자

public class DouglasPeucker { 

private double epsilon; 
protected Point[] coinImage; 

public DouglasPeucker(Point [] tab) { 
    this.coinImage = new Point[tab.length]; 
    for(int i = 0; i < this.coinImage.length; i++) { 
     double abscisse = tab[i].getX(); 
     double ordonnee = tab[i].getY(); 
     System.out.println(abscisse + " " + ordonnee); 
     this.coinImage[i].setX(abscisse); 
     this.coinImage[i].setY(ordonnee); 
    } 
} 
+0

오류가 무엇입니까 당신은 뭔가를해야합니까? – mre

답변

3

당신은 결코 coinImage[i]에 값을 할당하지있어, 그래서 당신이 역 참조있어 null의 기본 값을 갖게됩니다. IMO

for(int i = 0; i < this.coinImage.length; i++) { 
    double abscisse = tab[i].getX(); 
    double ordonnee = tab[i].getY(); 
    System.out.println(abscisse + " " + ordonnee); 
    this.coinImage[i] = new Point(); 
    this.coinImage[i].setX(abscisse); 
    this.coinImage[i].setY(ordonnee); 
} 

또는 양호하게는, :

for (int i = 0; i < this.coinImage.length; i++) { 
    // I'm assuming Point has a sensible constructor here... 
    coinImage[i] = new Point(tab[i].getX(), tab[i].getY()); 
    // Insert the diagnostics back in if you really need to 
} 
+0

너는 나보다 너무 빠르다! +1 – Jomoos

+0

오, 바보 같은 오류! 도와 주셔서 감사합니다 ! – afk