skip to Main Content

I have a javafx project that I want to compile. Its source code is composed of two classes ‘App.java’ and ‘Main.java’ located in the same package name ‘app’.

Main.java code:

package h4131.app;

public class Main {
    public static void main(String [] args){
        App.main(args);
    }
}

App.java code:


package h4131.app;

import javafx.application.Application;
import javafx.stage.Stage;

import java.io.IOException;

import h4131.view.WindowBuilder;

/**
 * JavaFX App
 */
public class App extends Application {

    @Override
    public void start(Stage stage) throws IOException {
        // WindowBuilder windowBuilder = new WindowBuilder(stage);
    }

    public static void main(String[] args) {
        launch();
    }

}

Basically, when the Main.java class is compiled, it should calls the main function of the App class and should then produce an executable named ‘agile.jar’.

But when compiling Main.java, I get the following error:

Main.java:5: error: cannot find symbol
App.main(args);
^
symbol: variable App
location: class Main
1 error
error: compilation failed

It seems that it can’t find the App.java class located in the same package and I don’t understand why.

The tricky part is that I can launch the executable with a shell outside of Vscode with this command : java -jar agile.jar

So the problem might be with vscode.

I tried to delete and reinstall the JPK, Java, I changed the path variable to the right location, I restarted my computer, rebuilt the project in vscode but none of that seems to work.

I’m asking for your help and support, hoping that you’ll find a solution.

Thanks in advance for your answer.

Cheers guys.

2

Answers


  1. Why not just use IDE like IntelliJ? Even in free version it can easily autoconfigure compiling and launching an app.

    Login or Signup to reply.
  2. Try the following command and rebuild:

    Ctrl+Shift+P –> Java: Clean Java Language Server Workspace

    enter image description here

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