When I create a java package inside the src
folder in the java project I am working on, without using any package, everything works just fine, just when I create that package folder and move all my java files to it though all the files have the package name correct in them and everything else is correct, but I get these 2 errors below, i will provide you with some screenshots to better understand the situation.
Main.java:6: error: cannot find symbol
Circle2D c1 = new Circle2D(2,2,5.5);
^
symbol: class Circle2D
location: class Main
Main.java:6: error: cannot find symbol
Circle2D c1 = new Circle2D(2,2,5.5);
^
symbol: class Circle2D
location: class Main
Main.java:7: error: cannot find symbol
System.out.println(c1.getArea()+" "+ c1.getPerimeter()+" "+c1.contains(3,3)+" "+c1.contains(new Circle2D(4, 5, 10.5)));
^
symbol: class Circle2D
location: class Main
Main.java:8: error: cannot find symbol
System.out.println(c1.overlaps(new Circle2D(3,5,2.3)));
^
symbol: class Circle2D
location: class Main
4 errors
The only thing that worked is instead of running the code with "Run Code" button of the code runner extension I used "Run Java" but I don’t like to use it because it prints so much clutter and using the code runner features gives a clean output.
2
Answers
it seems that your classes are trying to find each other in the current directory.
To "route" them in the right way:
.vscode
. Visual Studio Code will orient on files in it when decides where to look for your.java
files.settings.json
file inProject1.vscode
.settings.json
with the following text:You’re supposed to get result like this.
If it stil does not work go to settings (Ctrl+,), type "launch" and get a single option. Selecting it will send you to global settings file, where you should find
"configurations": []
and fill[]
with the following:You should use the official Extension Pack for Java and use it to execute your java project (Run Java). If you use other extensions that cause errors, it has nothing to do with Java.
Code Runner is only used for executing code, it doesn’t have much advantage for complete projects, please use official extensions.
https://code.visualstudio.com/docs/java/java-tutorial