skip to Main Content

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


  1. reload VS Code window or F1 ->Clean the java language server workspace. try this could help

    Login or Signup to reply.
  2. 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 Runner

    Run Java and Debug Java are provided by the official extension

    enter image description here

    You can ask questions about the Code Runne here.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search