2

The following program is supplied in a textbook that I'm following. It should compute the distance between two coordinates (x1, y1) and (x2, y2) using the Point2D class:

import java.util.Scanner;
import javafx.geometry.Point2D;

public class TestPoint2D {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        System.out.print("Enter point1's x-, y-coordinates");
        double x1 = input.nextDouble();
        double y1 = input.nextDouble();
        System.out.print("Enter point2's x-, y coordinates");
        double x2 = input.nextDouble();
        double y2 = input.nextDouble();

        Point2D p1 = new Point2D(x1, y2);
        Point2D p2 = new Point2D(x2, y2);
        System.out.println("p1 is " + p1.toString());
        System.out.println("p2 is " + p2.toString());
        System.out.println("The distance between p1 and p2 is " +
            p1.distance(p2));
    }
}

I have looked over it many, many times, and made sure it is correctly copied. When I try to compile the program in my terminal, I get the following error messages:

import javafx.geometry.Point2D;
                      ^
TestPoint2D.java:15: error: cannot find symbol
        Point2D p1 = new Point2D(x1, y2);
        ^
  symbol:   class Point2D
  location: class TestPoint2D
TestPoint2D.java:15: error: cannot find symbol
        Point2D p1 = new Point2D(x1, y2);
                         ^
  symbol:   class Point2D
  location: class TestPoint2D
TestPoint2D.java:16: error: cannot find symbol
        Point2D p2 = new Point2D(x2, y2);
        ^
  symbol:   class Point2D
  location: class TestPoint2D
TestPoint2D.java:16: error: cannot find symbol
        Point2D p2 = new Point2D(x2, y2);
                         ^
  symbol:   class Point2D
  location: class TestPoint2D
5 errors

Why won't the program recognize the new Point2D objects?

alexwlchan
  • 5,699
  • 7
  • 38
  • 49
Sifu
  • 153
  • 1
  • 17

1 Answers1

2

What you are missing is jar for JavaFX runtime jar, refer to this question here on SO What's the location of the JavaFX runtime JAR file, jfxrt.jar, on Linux?

it provides a detailed explanation about the location of jfxrt.jar in Java 7 and 8.

Hope this helps !!

Community
  • 1
  • 1
Shrikant Havale
  • 1,250
  • 1
  • 16
  • 36