The import sun.security.ec cannot be resolved

Viewed 738

I just started Java in visual studio code.

import sun.security.ec.point.Point;

public class Tutorial {
    public static void main(String[] args) {

        Point point1 = new Point(x:1,y:2);
        System.out.println(point1);
    }
}

After run the code, it shows the below warning:

The import sun.security.ec cannot be resolved

Point cannot be resolved to a type

x cannot be resolved to a variable

y cannot be resolved to a variable

Do anyone know why this happen? And anyway to solve this?

2 Answers

Probably, you are looking for java.awt.Point. Moreover, the syntax to initialize Point (i.e. new Point(x:1,y:2)) is wrong. Do it as follows:

import java.awt.Point;

public class Main {
    public static void main(String[] args) {
        Point point1 = new Point(1, 2);
        System.out.println(point1);
    }
}

Output:

java.awt.Point[x=1,y=2]

Are you sure you need this particular import sun.security.ec.point.Point ? May be you were trying to import your own class from different package ?

Point from this package is interface https://java-browser.yawk.at/java/13/jdk.crypto.ec/sun/security/ec/point/Point.java

Therefore it does not have a constructor.

Syntax new Point(x: 1, y: 2); not related to java.

Your code should look like this:

public class Tutorial {
    public static void main(String[] args) {

        int x = 1;
        int y = 2;

        Point point1 = new Point(x, y);

        System.out.println(point1);
    }
}
Related