0

so I dug into JavaFX for the last few days while following a tutorial https://www.youtube.com/watch?v=FLkOX4Eez6o&list=PL6gx4Cwl9DGBzfXLWLSYVy8EbTdpGbUIG. Now my problem is, that I cant run a project with a .fxml file in it. My code: Main:

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("/main.fxml"));
      primaryStage.setTitle("Hello World");
      primaryStage.setScene(new Scene(root, 300, 275));
      primaryStage.show();
   }


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

Controller:

package main.java.research;
import javafx.scene.control.Button;
public class Controller {

   public void handleButtonClick(){
       System.out.println("Run code in console");

   }
}

FXML-File:

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<VBox prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8"xmlns:fx="http://javafx.com/fxml"
  fx:controller="main.java.research.Controller">

    <Label text="I love bacon"/>
    <Button text="Submit"/>

</VBox>

Error-Message:

"C:\Program Files\Java\jdk-13.0.2\bin\java.exe" -p C:\JavaFX\javafx-sdk-14\lib --add-modules javafx.controls,javafx.fxml --add-modules javafx.base,javafx.graphics --add-reads javafx.base=ALL-UNNAMED --add-reads javafx.graphics=ALL-UNNAMED "-javaagent:C:\Users\Standard\AppData\Local\JetBrains\IntelliJ IDEA Community Edition 2019.3.3\lib\idea_rt.jar=54742:C:\Users\Standard\AppData\Local\JetBrains\IntelliJ IDEA Community Edition 2019.3.3\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\Standard\IdeaProjects\FXML-Shit\out\production\FXML-Shit;C:\JavaFX\javafx-sdk-14\lib\javafx-swt.jar;C:\JavaFX\javafx-sdk-14\lib\javafx.base.jar;C:\JavaFX\javafx-sdk-14\lib\javafx.controls.jar;C:\JavaFX\javafx-sdk-14\lib\javafx.fxml.jar;C:\JavaFX\javafx-sdk-14\lib\javafx.graphics.jar;C:\JavaFX\javafx-sdk-14\lib\javafx.media.jar;C:\JavaFX\javafx-sdk-14\lib\javafx.swing.jar;C:\JavaFX\javafx-sdk-14\lib\javafx.web.jar main.java.research.Main
Exception in Application start method
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
    at java.base/java.lang.Thread.run(Thread.java:830)
Caused by: javafx.fxml.LoadException: 
/C:/Users/Standard/IdeaProjects/FXML-Shit/out/production/FXML-Shit/main.fxml

    at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2568)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3237)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3194)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3163)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3136)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3113)
    at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3106)
    at main.java.research.Main.start(Main.java:13)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    ... 1 more
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[2,6]
Message: The processing instruction target matching "[xX][mM][lL]" is not allowed.
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:652)
    at java.xml/javax.xml.stream.util.StreamReaderDelegate.next(StreamReaderDelegate.java:84)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2538)
    ... 17 more
Exception running application main.java.research.Main

Structure: https://i.stack.imgur.com/0tVPk.jpg

I researched the problem and stumbled across an thread that had a simular problem (JavaFX InvocationTargetException). I used the solution on my project but still got the problems I had before. Now I need some new ideas on how to fix that, since I have no idea what to do. I use InteliJ Community Edition and JavaFX 14. I would not rule out an installation error.

Do you have any ideas on how to fix it?

  • JavaFX11+ is modular Look at "modular java" and how to use the module-info.java to export javaFX modules to your project: [releated thread](https://stackoverflow.com/questions/51843208/running-javafx-sample-on-jdk-11-with-openjfx-11-jmods-on-module-path) Also a videos tutorial of it: https://www.youtube.com/watch?v=WtOgoomDewo . Alternatively you can use gradle to export the required Modules to your project. – Luxusproblem Apr 12 '20 at 11:32
  • Your problem is different to the one in the question linked by you. Hint: Starting to read the "Caused by" parts of the stacktrace from the bottom is usually a good idea, since those parts are closest to the root cause. In this case the xml parser fails to read the fxml, since the ` – fabian Apr 12 '20 at 13:35

0 Answers0