2016-08-09 108 views
0
Hi I want to initialize an array of Point2D (Point2D.Double []) 
Somehow I fail, I get the following error: 

Exception in thread "main" java.lang.NoSuchMethodError: java.awt.geom.Point2D.createArray() [Ljava/AWT/geom/Point2D $ Doppelt; bei MainClass.main (MainClass.java:20)java.awt.geom.Point2D.createArray()

***The purpose of the program:*** 
In the main there to produce an array of length 10,000 may be incorporated into the data structures and another 100,000 long array of points that will be submitted once the data structure to return the closest point. 
I would like to build two data structures and move them all the points and make sure I get every time the same result in both. 

    import java.awt.Component; 
import java.awt.List; 
import java.awt.geom.Point2D; 
import java.awt.geom.Point2D.Double; 
import java.lang.reflect.Array; 
import java.util.ArrayList; 
import java.util.Vector; 

public class MainClass { 
    private static final int N = 10000; 
    static Vector<Point2D> coords = new Vector<Point2D>(); 
    static Point2D newCoords; 
    Point2D oldCoords; 



    public static void main(String[] args) { 
     final long startTime = System.nanoTime(); 
     Point2D.Double[] points=Point2D.createArray(); 

in this line i get the error.

 static void setDisplayParams(Vector<Point2D> coords, double xMin, double xMax, double yMin, double yMax){ 
      Point2D newCoords, oldCoords; 
      Vector<Point2D> displayCoords = new Vector<Point2D>(); 
      for (int i=0; i<coords.size(); ++i){ 
       oldCoords=coords.elementAt(i); 
       newCoords=coords.elementAt(i); 
       //     newCoords.setLocation(oldCoords.getDoublePointVarX(), yMax-oldCoords.getDoublePointVarY()); 
       displayCoords.add(newCoords); 
       displayParams.displayCoords.add(new Point2D.Double(newCoords.getX(), yMax-newCoords.getY())); 
      } 

//here i check the duration of the RunTime program

  final long duration = System.nanoTime() - startTime; 
      System.out.println(duration); 


     } 

// Klasse Point2D Paket java.awt.geom;

public class Point2D implements Comparable<Point2D> { 
    public class Double extends Point2D { 



     //****************************************** Variables ****************************************************** 

     private double x; 
     private double y; 

     //****************************************** Constructor ************************************************* 
     public Double(double x, double y) { 
      super(x, y); 

     } 
     //****************************************** Getters & Setters ************************************************* 
     public double getX() { 
      return x; 
     } 
     public void setX(double x) { 
      this.x = x; 
     } 
     public double getY() { 
      return y; 
     } 
     public void setY(double y) { 
      this.y = y; 
     } 

    } 
    private double y; 
    private double x; 


    public Point2D(double x, double y) { 
     this.x = x; 
     this.y = y; 
    } 


    //****************************************** Other Methods ************************************************* 
    public double distanceTo(Point2D that) { 
     double dx = this.x - that.x; 
     double dy = this.y - that.y; 
     return Math.sqrt(dx*dx + dy*dy); 
    } 

check the distance between to points.

public int compareTo(Point2D p, Point2D q) { 
     double dist1 = distanceTo(p); 
     double dist2 = distanceTo(q); 
     if  (dist1 < dist2) return -1; 
     else if (dist1 > dist2) return +1; 
     else     return 0; 
    } 
    @Override 
    public int compareTo(Point2D o) { 
     return 0; 
    } 


    public static Point2D.Double[] createArray(){ 
     Point2D.Double[] points = new Point2D.Double[10000]; 
     for (int i = 0; i < 10000; ++i) { 
      double x = Math.random(); 
      double y = Math.random(); 
      points[i]=(Double) new Point2D(x, y); 
     } 
     return points; 
    } 
} 

Antwort

1

Ihre createArray() Parameter erfolgt nicht. Du rufst es mit zwei an. Daher der Fehler.