Trying to launch a JavaFX application, catching exception in Application start method. There is a suspicion that problems are in the path to the .fxml file.
public class Main extends Application implements Observer { private static final String FXML_MAIN = "fxml/main.fxml"; public static final String BUNDLES_FOLDER = "Locale"; private Stage primaryStage; private MainController mainController; private FXMLLoader fxmlLoader; private VBox currentRoot; @Override public void start(Stage primaryStage) throws Exception { this.primaryStage = primaryStage; createGUI(LocaleManager.RU_LOCALE); } public static void main(String[] args) { launch(args); } @Override public void update(Observable o, Object arg) { Lang lang = (Lang) arg; VBox newNode = loadFXML(lang.getLocale()); // получить новое дерево компонетов с нужной локалью currentRoot.getChildren().setAll(newNode.getChildren()); // заменить старые дочерник компонента на новые - с другой локалью } // загружает дерево компонентов и возвращает в виде VBox (корневой элемент в FXML) private VBox loadFXML(Locale locale) { fxmlLoader = new FXMLLoader(); fxmlLoader.setLocation(getClass().getResource(FXML_MAIN)); fxmlLoader.setResources(ResourceBundle.getBundle(BUNDLES_FOLDER, locale)); VBox node = null; try { node = (VBox) fxmlLoader.load(); mainController = fxmlLoader.getController(); mainController.addObserver(this); primaryStage.setTitle(fxmlLoader.getResources().getString("address_book")); } catch (IOException e) { e.printStackTrace(); } return node; } private void createGUI(Locale locale) { currentRoot = loadFXML(locale); Scene scene = new Scene(currentRoot, 300, 275); primaryStage.setScene(scene); primaryStage.setMinHeight(600); primaryStage.setMinWidth(400); primaryStage.show(); } } And this is the error output:
Exception in Application start method java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389) at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767) Caused by: java.lang.RuntimeException: Exception in Application start method at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$154(LauncherImpl.java:182) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.IllegalStateException: Location is not set. at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409) at start.Main.loadFXML(Main.java:56) at start.Main.createGUI(Main.java:68) at start.Main.start(Main.java:33) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326) at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294) at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177) ... 1 more Exception running application start.Main What could be the problem and how to fix it?
getClass()- Maxim