I am coding java on vscode. I have source folder:
>...
>lib
>>src
exam1.java
exam1.class
>>Month10
app1.class
app1.java
With:
exam1.java
public class exam1 {
public static void main(String[] args) {
System.out.println("Hello world");
}
}
app1.java
package Month10;
public class app1 {
public static void main(String[] args) {
System.out.println("Hello world");
}
}
I want to ask about why I need to use package Month10 in here. And another, exam1.java run well(both run code and run java), but in app1.java, I only can "run java", can’t "run code" (Ctrl+Alt+N in vs code), it exists error Could not find or load main class app1, I think because the command package? (I saved file before running), can anyone help me, thanks.
2
Answers
reload VS Code window or F1 ->Clean the java language server workspace. try this could help
The Code Runner extension sometimes has problems running code under multiple levels of folders. For a better coding experience, please use the official extension to run the code.
Tips:
Run Code
is provided by Code RunnerRun Java
andDebug Java
are provided by the official extensionYou can ask questions about the Code Runne here.