FXML: StackPane als Root-Element

iTobi97

Aktives Mitglied
Hallo liebe Community,
ich habe ein kleines Problem mit einem FXML-Dokument, das ich erstellt habe.

Ich habe in dieser FXML-Datei einen StackPane als Root-Element verwendet. Da ich allerdings eine LoadException am Ende des Root-Elements (öffnenden Tags) bekomme, vermute ich stark, dass an dieser Stelle ein Problem mit dem StackPane besteht.

XML:
<StackPane xmlns="http://javafx.com/javafx"
           xmlns:fx="http://javafx.com/fxml"
           fx:controller="frontend.FXMLController"
           prefHeight="400.0" prefWidth="600.0" stylesheets="style.css">

    <VBox spacing="5">
        <Button text="New Game" fx:id="buttonNewGame" styleClass="button"/>
        <Button text="Load Game" fx:id="buttonLoadGame" styleClass="button"/>
        <Button text="Exit Game" fx:id="buttonExitGame" styleClass="button"/>
        <Button text="Resume" fx:id="buttonResumeGame" styleClass="button"/>
        <Button text="Save Game" fx:id="buttonSaveGame" styleClass="button"/>
        <Button text="Restart Game" fx:id="buttonRestartGame" styleClass="button"/>
        <Button text="Main Menu" fx:id="buttonMainMenu" styleClass="button"/>
    </VBox>
    <BorderPane>
        <center>
            <GridPane fx:id="gameBoardFieldsGrid">

            </GridPane>
        </center>
        <right>
            <VBox>
                <Label fx:id="labelStatusMessage"/>
                <ImageView>
                    <Image url="cardbkrita.png"/>
                </ImageView>
                <HBox fx:id="movementCardsHBox">

                </HBox>
                <Button text="Pause" fx:id="buttonPause"/>
            </VBox>
        </right>
    </BorderPane>
</StackPane>

Ich hoffe, jemand von euch kann mir schnell bei der Behebung dieses Fehlers helfen.
Viele Grüße
 
Zuletzt bearbeitet von einem Moderator:
Code:
javafx.fxml.LoadException: Dateipfad/Dateiname.fxml:14
    at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625)
    at javafx.fxml/javafx.fxml.FXMLLoader.access$700(FXMLLoader.java:105)
    at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:941)
    at javafx.fxml/javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:980)
    at javafx.fxml/javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:227)
    at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:752)
    at javafx.fxml/javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2722)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3253)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3210)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3179)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3152)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3129)
    at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3122)
    at frontend.GameBoard.<init>(GameBoard.java:139)
    at frontend.GUI.start(GUI.java:38)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:919)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
    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:175)
    at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.lang.InstantiationException: frontend.FXMLController
    at java.base/java.lang.Class.newInstance(Class.java:545)
    at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:936)
    ... 23 more
Caused by: java.lang.NoSuchMethodException: frontend.FXMLController.<init>()
    at java.base/java.lang.Class.getConstructor0(Class.java:3322)
    at java.base/java.lang.Class.newInstance(Class.java:530)
    ... 24 more
Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:973)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:198)
    at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.lang.NullPointerException
    at frontend.GameBoard.<init>(GameBoard.java:146)
    at frontend.GUI.start(GUI.java:38)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:919)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
    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:175)
    ... 1 more
 
Code:
Caused by: java.lang.NoSuchMethodException: frontend.FXMLController.<init>()

Deine Controller-Klasse hat keinen parameter-losen Konstruktor
 
Zuletzt bearbeitet:
@mrBrown Vielen Dank, dieser Fehler ist verschwunden, allerdings habe ich immer noch eine LoadException, nur dieses Mal ohne Zeilenangabe:

Code:
javafx.fxml.LoadException:  Dateipfad/Datei.fxml

    at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2603)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3253)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3210)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3179)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3152)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3129)
    at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3122)
    at frontend.GameBoard.<init>(GameBoard.java:139)
    at frontend.GUI.start(GUI.java:38)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:919)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
    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:175)
    at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.lang.NullPointerException
    at frontend.FXMLController.initialize(FXMLController.java:47)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2573)
    ... 18 more
Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:973)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:198)
    at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.lang.NullPointerException
    at frontend.GameBoard.<init>(GameBoard.java:146)
    at frontend.GUI.start(GUI.java:38)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:919)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
    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:175)
    ... 1 more

Die XML-Datei versuche ich folgendermaßen aufzurufen:
Code:
StackPane root = (StackPane)FXMLLoader.load(getClass().getResource("GameBoard.fxml"));
 
Code:
Caused by: java.lang.NullPointerException
    at frontend.FXMLController.initialize(FXMLController.java:47)
Guck mal in Zeile 47 in deinem Controller, dort gibt es einen NullPointer...
 

Neue Themen


Zurück
Oben