0
//This is the default code VSC creates for a javafx file.
//It is giving an error message of "Error: Main method not found in the file,
//please define the main method as: public static void main(String[] args)"

package com.example;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;

/**
 * JavaFX App
 */
public class App extends Application {
     private static Scene scene;
     @Override
     public void start(Stage stage) throws IOException {
        scene = new Scene(loadFXML("primary"), 640, 480);
        stage.setScene(scene);
        stage.show();
     }

     static void setRoot(String fxml) throws IOException {
         scene.setRoot(loadFXML(fxml));
     }

     private static Parent loadFXML(String fxml) throws IOException {
         FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml"));
         return fxmlLoader.load();
     }

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

}

My java projects suddenly stopped working in Virtual Studio Code. I started a new javafx project and tried to run it, but it's giving me an error saying that there is no main method, even though I have a correctly defined main method. I tried running a default javafx program that VSC creates, and even their own project didn't run, giving the same error. I am also getting an error that pom.xml needs to be updated, but I tried to update it and it didn't help. What am I missing or how can I fix this? I have an internet filter which I thought might be causing problems, but I have run java projects in VSC since getting the filter, and I specifically had them allow http://plugins.gradle.org, http://oracle.com, and maven.apache.org.

In the pom.xml file, I changed the version number under to the latest version number. I tried closing and restarting the project and running maven clean install and maven clean in the terminal.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
      <groupId>com.example</groupId>
      <artifactId>demo</artifactId>
      <version>1.0-SNAPSHOT</version>
      <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <maven.compiler.source>11</maven.compiler.source>
         <maven.compiler.target>11</maven.compiler.target>
      </properties>
      <dependencies>
         <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>13</version>
         </dependency>
         <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>13</version>
         </dependency>
      </dependencies>
      <!-- ... -->
</project>
M. Yousfi
  • 578
  • 5
  • 24
Mrs. A KF
  • 1
  • 2
  • 1
    please edit your post sharing log messages from visual sutdio code and a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) if possible. – Gastón Schabas Jun 06 '23 at 01:37
  • have you tried to rename `.vscode` directory to something else and reload the project? also, [configuring main method in `pom.xml`](https://stackoverflow.com/a/29920526) – Bagus Tesa Jun 06 '23 at 02:50
  • we would need more debugging details or at least a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) to help you. VS Code should have log files saying what is the IDE doing, what are the commands that are being executed to run your app. Also, have you tried to run the app from the command line using maven? – Gastón Schabas Jun 06 '23 at 16:08
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Please see [how to ask](https://stackoverflow.com/help/how-to-ask). [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) – JialeDu Jun 07 '23 at 07:48
  • May I know what's going on with the problem? If it has been solved, can you change the status of the answer to help more people with similar problems. – JialeDu Jun 30 '23 at 01:19

0 Answers0