0

After I tried to connect to my buttons to Controller class I've got an errorProblem with Exception in Application start method in IDE.

I did read/try all the advices like getClassLoader(), do "/sample.fxml" , put the file together with MAIN, but nothing helped. Please help me to spot the issue.

The structure is :

scr
   sample
         Controller
         Main
         sample.fxml

So, the pass "sample.fxml" looks fine. What else could be an issue?

 package sample;

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

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
        primaryStage.setTitle("Hello World");
        primaryStage.setScene(new Scene(root, 300, 275));
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}
fabian
  • 80,457
  • 12
  • 86
  • 114
  • 1
    Please [edit] your question to add the _full_ [stack trace](https://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors). – Slaw May 19 '19 at 16:10
  • Did you try the advice of using `getClass().getResource("/sample/sample.fxml")` (which I'm pretty sure was already posted for one of a the similar questions? BTW: The stacktrace includes a line similar to `Caused by: ... Location required` (last part may also be `location not set`)? There could be a ton of other reasons involved here: non-wellformed fxml file, `Controller` class not adhereing to the requirements, module not providing access to controller class (or not declaring a module at all in some of the newer java versions), ... – fabian May 19 '19 at 22:36

1 Answers1

0

Try this.

Parent root = FXMLLoader.load(getClass().getResource("/sample/sample.fxml"));
Scene scene = new Scene(root);
primaryStage.setTitle("Hello World");
primaryStage.setScene(scene);
primaryStage.show();
Mayur Patel
  • 319
  • 1
  • 2
  • 13