Почему у меня возникает эта ошибка при попытке переключить сцены в JavaFX с помощью ScenBuilder?

#java #javafx #scenebuilder

Вопрос:

Я изучал графический интерфейс Java для школьного проекта (настройка службы заказа еды) и столкнулся с проблемой при попытке переключить сцены. Раньше код работал, но я внес некоторые изменения в дизайн «Order.fxml», и теперь я, похоже, не могу найти проблему.

Основной Класс

 package application;
    
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) {
        try {
            Parent root =FXMLLoader.load(getClass().getResource("Welcome.fxml"));
            Scene scene = new Scene(root,600,400);
            scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
    
    public static void main(String[] args) {
        launch(args);
    }
}
 

Класс Контроллера

 package application;

import java.io.IOException;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;

public class Controller {
    @FXML
    Button buttonyes,buttonno;

    private Stage stage;
    private Scene scene;
    private Parent root;

    public void yes(ActionEvent event) throws IOException {
        root = FXMLLoader.load(getClass().getResource("Order.fxml"));
        stage = (Stage)((Node)event.getSource()).getScene().getWindow();
        scene = new Scene(root);
        stage.setScene(scene);
        stage.show();
    }

    public void no(ActionEvent event) {
        System.exit(0);
    }
}
 

Контроллер заказов для Order.fxml

 package application;

import java.io.IOException;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;

public class OrderController {
    @FXML 
    private Stage stage;
    private Scene scene;
    private Parent root;
    
    Button buttonorder;
    Button buttonclear;
    Button buttonback;

    public void back(ActionEvent event) throws IOException {
         root = FXMLLoader.load(getClass().getResource("Welcome.fxml"));
         stage = (Stage)((Node)event.getSource()).getScene().getWindow();
         scene = new Scene(root);
         stage.setScene(scene);
         stage.show();
    }
}
 

Welcome.fxml

 <?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.shape.Rectangle?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller">
   <children>
      <ImageView fitHeight="281.0" fitWidth="267.0" layoutX="14.0" layoutY="60.0">
         <image>
            <Image url="@../../../../../OneDrive/Documents/Schule/lockdown 2/info/projektarbeit/menu.png" />
         </image>
      </ImageView>
      <Rectangle arcHeight="5.0" arcWidth="5.0" fill="#e88c38" height="400.0" layoutX="295.0" stroke="TRANSPARENT" strokeType="INSIDE" width="305.0" />
      <Text fill="#e2e2e2" layoutX="323.0" layoutY="154.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Herzlich Willkommen!">
         <font>
            <Font name="Arial Black" size="21.0" />
         </font>
      </Text>
      <Text fill="#e2e2e2" layoutX="338.0" layoutY="180.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Möchten Sie bestellen?">
         <font>
            <Font name="Arial" size="21.0" />
         </font>
      </Text>
      <Button fx:id="buttonyes" layoutX="381.0" layoutY="214.0" mnemonicParsing="false" onAction="#yes" style="-fx-background-color: #e2e2e2;" text="Ja">
         <font>
            <Font name="Arial Black" size="15.0" />
         </font>
      </Button>
      <Button fx:id="buttonno" layoutX="456.0" layoutY="214.0" mnemonicParsing="false" onAction="#no" style="-fx-background-color: #e2e2e2;" text="Nein">
         <font>
            <Font name="Arial Black" size="15.0" />
         </font>
      </Button>
   </children>
</AnchorPane>
 

Order.fxml

 <?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.text.Font?>

<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="781.0" xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller">
   <children>
      <Pane layoutX="181.0" prefHeight="150.0" prefWidth="200.0" style="-fx-border-color: lightgrey;">
         <children>
            <ImageView fitHeight="118.0" fitWidth="118.0" layoutX="41.0">
               <image>
                  <Image url="@../../../../../OneDrive/Documents/Schule/lockdown 2/info/projektarbeit/pig.png" />
               </image>
            </ImageView>
            <Pane layoutX="-3.0" layoutY="112.0" prefHeight="42.0" prefWidth="207.0">
               <children>
                  <Label layoutX="14.0" layoutY="3.0" text="Hamburger">
                     <font>
                        <Font name="Arial Black" size="14.0" />
                     </font>
                  </Label>
                  <Label layoutX="14.0" layoutY="20.0" text="3€">
                     <font>
                        <Font name="Arial" size="15.0" />
                     </font>
                  </Label>
                  <ChoiceBox layoutX="137.0" layoutY="8.0" prefHeight="22.0" prefWidth="56.0" />
               </children>
            </Pane>
         </children>
      </Pane>
      <Pane layoutX="181.0" layoutY="150.0" prefHeight="150.0" prefWidth="200.0" style="-fx-border-color: lightgrey;">
         <children>
            <ImageView fitHeight="110.0" fitWidth="111.0" layoutX="45.0">
               <image>
                  <Image url="@../../../../../OneDrive/Documents/Schule/lockdown 2/info/projektarbeit/hen.png" />
               </image>
            </ImageView>
            <Pane layoutX="-3.0" layoutY="108.0" prefHeight="42.0" prefWidth="207.0">
               <children>
                  <Label layoutX="14.0" layoutY="3.0" text="Chickenburger ">
                     <font>
                        <Font name="Arial Black" size="14.0" />
                     </font>
                  </Label>
                  <Label layoutX="14.0" layoutY="20.0" text="3€">
                     <font>
                        <Font name="Arial" size="15.0" />
                     </font>
                  </Label>
                  <ChoiceBox layoutX="137.0" layoutY="8.0" prefHeight="22.0" prefWidth="56.0" />
               </children>
            </Pane>
         </children>
      </Pane>
      <Pane layoutX="181.0" layoutY="300.0" prefHeight="150.0" prefWidth="200.0" style="-fx-border-color: lightgrey;">
         <children>
            <ImageView fitHeight="110.0" fitWidth="111.0" layoutX="45.0">
               <image>
                  <Image url="@../../../../../OneDrive/Documents/Schule/lockdown 2/info/projektarbeit/nuggets.png" />
               </image>
            </ImageView>
            <Pane layoutX="-3.0" layoutY="108.0" prefHeight="42.0" prefWidth="207.0">
               <children>
                  <Label layoutX="14.0" layoutY="3.0" text="Nuggets">
                     <font>
                        <Font name="Arial Black" size="14.0" />
                     </font>
                  </Label>
                  <Label layoutX="14.0" layoutY="20.0" text="2€">
                     <font>
                        <Font name="Arial" size="15.0" />
                     </font>
                  </Label>
                  <ChoiceBox layoutX="137.0" layoutY="9.0" prefHeight="22.0" prefWidth="56.0" />
               </children>
            </Pane>
         </children>
      </Pane>
      <Pane layoutX="181.0" layoutY="450.0" prefHeight="150.0" prefWidth="200.0" style="-fx-border-color: lightgrey;">
         <children>
            <ImageView fitHeight="139.0" fitWidth="139.0" layoutX="-17.0" layoutY="6.0">
               <image>
                  <Image url="@../../../../../OneDrive/Documents/Schule/lockdown 2/info/projektarbeit/soft-drink.png" />
               </image>
            </ImageView>
            <Pane layoutX="95.0" layoutY="-4.0" prefHeight="159.0" prefWidth="111.0">
               <children>
                  <Label layoutX="33.0" layoutY="30.0" text="Sprite">
                     <font>
                        <Font name="Arial Black" size="14.0" />
                     </font>
                  </Label>
                  <Label layoutX="47.0" layoutY="52.0" text="1€">
                     <font>
                        <Font name="Arial" size="15.0" />
                     </font>
                  </Label>
                  <ChoiceBox layoutX="28.0" layoutY="88.0" prefHeight="22.0" prefWidth="56.0" />
               </children>
            </Pane>
         </children>
      </Pane>
      <Pane layoutX="381.0" prefHeight="150.0" prefWidth="200.0" style="-fx-border-color: lightgrey;">
         <children>
            <ImageView fitHeight="118.0" fitWidth="118.0" layoutX="47.0">
               <image>
                  <Image url="@../../../../../OneDrive/Documents/Schule/lockdown 2/info/projektarbeit/cheese.png" />
               </image>
            </ImageView>
            <Pane layoutX="-3.0" layoutY="108.0" prefHeight="42.0" prefWidth="207.0">
               <children>
                  <Label layoutX="14.0" layoutY="3.0" text="Cheeseburger ">
                     <font>
                        <Font name="Arial Black" size="14.0" />
                     </font>
                  </Label>
                  <Label layoutX="14.0" layoutY="20.0" text="2,50€">
                     <font>
                        <Font name="Arial" size="15.0" />
                     </font>
                  </Label>
                  <ChoiceBox layoutX="137.0" layoutY="9.0" prefHeight="22.0" prefWidth="56.0" />
               </children>
            </Pane>
         </children>
      </Pane>
      <Pane layoutX="381.0" layoutY="150.0" prefHeight="150.0" prefWidth="200.0" style="-fx-border-color: lightgrey;">
         <children>
            <ImageView fitHeight="102.0" fitWidth="102.0" layoutX="49.0">
               <image>
                  <Image url="@../../../../../OneDrive/Documents/Schule/lockdown 2/info/projektarbeit/pommes-frittes.png" />
               </image>
            </ImageView>
            <Pane layoutX="-3.0" layoutY="108.0" prefHeight="42.0" prefWidth="207.0">
               <children>
                  <Label layoutX="14.0" layoutY="3.0" text="Pommes ">
                     <font>
                        <Font name="Arial Black" size="14.0" />
                     </font>
                  </Label>
                  <Label layoutX="14.0" layoutY="20.0" text="1,50€">
                     <font>
                        <Font name="Arial" size="15.0" />
                     </font>
                  </Label>
                  <ChoiceBox layoutX="137.0" layoutY="9.0" prefHeight="22.0" prefWidth="56.0" />
               </children>
            </Pane>
         </children>
      </Pane>
      <Pane layoutX="381.0" layoutY="300.0" prefHeight="150.0" prefWidth="200.0" style="-fx-border-color: lightgrey;">
         <children>
            <ImageView fitHeight="110.0" fitWidth="111.0" layoutX="45.0">
               <image>
                  <Image url="@../../../../../OneDrive/Documents/Schule/lockdown 2/info/projektarbeit/ice-cream.png" />
               </image>
            </ImageView>
            <Pane layoutX="-3.0" layoutY="110.0" prefHeight="42.0" prefWidth="207.0">
               <children>
                  <Label layoutX="14.0" layoutY="3.0" text="Eis">
                     <font>
                        <Font name="Arial Black" size="14.0" />
                     </font>
                  </Label>
                  <Label layoutX="14.0" layoutY="20.0" text="1€">
                     <font>
                        <Font name="Arial" size="15.0" />
                     </font>
                  </Label>
                  <ChoiceBox layoutX="137.0" layoutY="8.0" prefHeight="22.0" prefWidth="56.0" />
               </children>
            </Pane>
         </children>
      </Pane>
      <Pane layoutX="381.0" layoutY="450.0" prefHeight="150.0" prefWidth="200.0" style="-fx-border-color: lightgrey;">
         <children>
            <ImageView fitHeight="128.0" fitWidth="128.0" layoutX="-17.0" layoutY="11.0">
               <image>
                  <Image url="@../../../../../OneDrive/Documents/Schule/lockdown 2/info/projektarbeit/soda.png" />
               </image>
            </ImageView>
            <Pane layoutX="89.0" prefHeight="159.0" prefWidth="111.0">
               <children>
                  <Label layoutX="33.0" layoutY="30.0" text="Fanta">
                     <font>
                        <Font name="Arial Black" size="14.0" />
                     </font>
                  </Label>
                  <Label layoutX="47.0" layoutY="52.0" text="1€">
                     <font>
                        <Font name="Arial" size="15.0" />
                     </font>
                  </Label>
                  <ChoiceBox layoutX="28.0" layoutY="88.0" prefHeight="22.0" prefWidth="56.0" />
               </children>
            </Pane>
         </children>
      </Pane>
      <Pane layoutX="581.0" prefHeight="150.0" prefWidth="200.0" style="-fx-border-color: lightgrey;">
         <children>
            <ImageView fitHeight="102.0" fitWidth="102.0" layoutX="49.0" layoutY="9.0">
               <image>
                  <Image url="@../../../../../OneDrive/Documents/Schule/lockdown 2/info/projektarbeit/ginkgo.png" />
               </image>
            </ImageView>
            <Pane layoutY="108.0" prefHeight="42.0" prefWidth="207.0">
               <children>
                  <Label layoutX="14.0" layoutY="3.0" text="Veggieburger">
                     <font>
                        <Font name="Arial Black" size="14.0" />
                     </font>
                  </Label>
                  <Label layoutX="14.0" layoutY="20.0" text="2€">
                     <font>
                        <Font name="Arial" size="15.0" />
                     </font>
                  </Label>
                  <ChoiceBox layoutX="137.0" layoutY="9.0" prefHeight="22.0" prefWidth="56.0" />
               </children>
            </Pane>
         </children>
      </Pane>
      <Pane layoutX="581.0" layoutY="150.0" prefHeight="150.0" prefWidth="200.0" style="-fx-border-color: lightgrey;">
         <children>
            <ImageView fitHeight="110.0" fitWidth="111.0" layoutX="45.0">
               <image>
                  <Image url="@../../../../../OneDrive/Documents/Schule/lockdown 2/info/projektarbeit/salad.png" />
               </image>
            </ImageView>
            <Pane layoutX="-3.0" layoutY="110.0" prefHeight="42.0" prefWidth="207.0">
               <children>
                  <Label layoutX="14.0" layoutY="3.0" text="Salat">
                     <font>
                        <Font name="Arial Black" size="14.0" />
                     </font>
                  </Label>
                  <Label layoutX="14.0" layoutY="20.0" text="2€">
                     <font>
                        <Font name="Arial" size="15.0" />
                     </font>
                  </Label>
                  <ChoiceBox layoutX="137.0" layoutY="8.0" prefHeight="22.0" prefWidth="56.0" />
               </children>
            </Pane>
         </children>
      </Pane>
      <Pane layoutX="581.0" layoutY="300.0" prefHeight="150.0" prefWidth="200.0" style="-fx-border-color: lightgrey;">
         <children>
            <ImageView fitHeight="139.0" fitWidth="139.0" layoutX="-15.0" layoutY="6.0">
               <image>
                  <Image url="@../../../../../OneDrive/Documents/Schule/lockdown 2/info/projektarbeit/cola.png" />
               </image>
            </ImageView>
            <Pane layoutX="89.0" layoutY="-4.0" prefHeight="159.0" prefWidth="111.0">
               <children>
                  <Label layoutX="39.0" layoutY="30.0" text="Cola">
                     <font>
                        <Font name="Arial Black" size="14.0" />
                     </font>
                  </Label>
                  <Label layoutX="47.0" layoutY="52.0" text="1€">
                     <font>
                        <Font name="Arial" size="15.0" />
                     </font>
                  </Label>
                  <ChoiceBox layoutX="28.0" layoutY="88.0" prefHeight="22.0" prefWidth="56.0" />
               </children>
            </Pane>
         </children>
      </Pane>
      <Pane layoutX="581.0" layoutY="450.0" prefHeight="150.0" prefWidth="200.0" style="-fx-border-color: lightgrey;">
         <children>
            <ImageView fitHeight="139.0" fitWidth="139.0" layoutX="-16.0" layoutY="6.0">
               <image>
                  <Image url="@../../../../../OneDrive/Documents/Schule/lockdown 2/info/projektarbeit/pepsi.png" />
               </image>
            </ImageView>
            <Pane layoutX="89.0" layoutY="-4.0" prefHeight="159.0" prefWidth="111.0">
               <children>
                  <Label layoutX="33.0" layoutY="30.0" text="Pepsi">
                     <font>
                        <Font name="Arial Black" size="14.0" />
                     </font>
                  </Label>
                  <Label layoutX="47.0" layoutY="52.0" text="1€">
                     <font>
                        <Font name="Arial" size="15.0" />
                     </font>
                  </Label>
                  <ChoiceBox layoutX="28.0" layoutY="88.0" prefHeight="22.0" prefWidth="56.0" />
               </children>
            </Pane>
         </children>
      </Pane>
      <Pane prefHeight="600.0" prefWidth="182.0" style="-fx-background-color: lightgrey;">
         <children>
            <Button fx:id="buttonorder" layoutX="41.0" layoutY="214.0" mnemonicParsing="false" onAction="#order" prefHeight="50.0" prefWidth="100.0" style="-fx-background-color: WHITE;" text="BESTELLEN">
               <font>
                  <Font name="Arial Black" size="11.0" />
               </font>
            </Button>
            <Button fx:id="buttonclear" layoutX="41.0" layoutY="275.0" mnemonicParsing="false" onAction="#clear" prefHeight="50.0" prefWidth="100.0" style="-fx-background-color: WHITE;" text="LÖSCHEN">
               <font>
                  <Font name="Arial Black" size="11.0" />
               </font>
            </Button>
            <Button fx:id="buttonback" layoutX="41.0" layoutY="336.0" mnemonicParsing="false" onAction="#back" prefHeight="50.0" prefWidth="100.0" style="-fx-background-color: WHITE;" text="ZURÜCK">
               <font>
                  <Font name="Arial Black" size="11.0" />
               </font>
            </Button>
         </children>
      </Pane>
   </children>
</AnchorPane>
 

Ошибка

 Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at javafx.fxml/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1862)
    at javafx.fxml/javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1729)
    at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
    at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
    at javafx.graphics/javafx.scene.Node.fireEvent(Node.java:8889)
    at javafx.controls/javafx.scene.control.Button.fire(Button.java:203)
    at javafx.controls/com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:208)
    at javafx.controls/com.sun.javafx.scene.control.inputmap.InputMap.handle(InputMap.java:274)
    at javafx.base/com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:247)
    at javafx.base/com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:234)
    at javafx.base/com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at javafx.base/com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at javafx.base/com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at javafx.base/com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.base/javafx.event.Event.fireEvent(Event.java:198)
    at javafx.graphics/javafx.scene.Scene$MouseHandler.process(Scene.java:3856)
    at javafx.graphics/javafx.scene.Scene.processMouseEvent(Scene.java:1851)
    at javafx.graphics/javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2584)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:409)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:299)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:447)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:412)
    at javafx.graphics/com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:446)
    at javafx.graphics/com.sun.glass.ui.View.handleMouseEvent(View.java:556)
    at javafx.graphics/com.sun.glass.ui.View.notifyMouse(View.java:942)
    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)
    at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at com.sun.javafx.reflect.Trampoline.invoke(MethodUtil.java:76)
    at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at javafx.base/com.sun.javafx.reflect.MethodUtil.invoke(MethodUtil.java:273)
    at javafx.fxml/com.sun.javafx.fxml.MethodHelper.invoke(MethodHelper.java:83)
    at javafx.fxml/javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1857)
    ... 46 more
Caused by: javafx.fxml.LoadException: Error resolving onAction='#order', either the event handler is not in the Namespace or there is an error in the script.
/C:/Users/daydr/eclipse-workspace/Projektarbeit-Bestellen/Bestellservice/bin/application/Order.fxml:308

    at javafx.fxml/javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2703)
    at javafx.fxml/javafx.fxml.FXMLLoader$Element.processEventHandlerAttributes(FXMLLoader.java:620)
    at javafx.fxml/javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:780)
    at javafx.fxml/javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2924)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2639)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3323)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3280)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3249)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3222)
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3199)
    at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:3192)
    at application.Controller.yes(Controller.java:23)
    ... 57 more
 

Я был бы очень признателен за любую помощь, которую вы можете мне оказать, так как это действительно расстраивает, пожалуйста, имейте в виду, что я только учусь этому 😀

Комментарии:

1. Ну, там написано: Error resolving onAction='#order' . Определение order метода в соответствующем контроллере отсутствует.

Ответ №1:

Следующие две строки отображаются в трассировке стека в вашем вопросе.

 Caused by: javafx.fxml.LoadException: Error resolving onAction='#order', either the event handler is not in the Namespace or there is an error in the script.
/C:/Users/daydr/eclipse-workspace/Projektarbeit-Bestellen/Bestellservice/bin/application/Order.fxml:308
 

Итак, проблема в файле Order.fxml . И проблема как-то связана со строкой onAction='#order' в этом файле.

Из содержимого этого файла, который вы опубликовали в своем вопросе, я вижу следующую строку:

 <Button fx:id="buttonorder" layoutX="41.0" layoutY="214.0" mnemonicParsing="false" onAction="#order" prefHeight="50.0" prefWidth="100.0" style="-fx-background-color: WHITE;" text="BESTELLEN">
 

Это означает, что при запуске приложения JavaFX и нажатии пользователем кнопки будет вызван order метод BESTELLEN. В каком классе должен появиться этот метод? В контроллере, указанном в файле Order.fxml . Опять же, в соответствии с тем, что вы опубликовали…

 <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="781.0" xmlns="http://javafx.com/javafx/15.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller">
 

класс контроллера таков Controller . Вы также опубликовали код этого класса в своем вопросе, но я не могу найти метод order в коде, который вы опубликовали. Объявление этого метода должно быть следующим, включая FXML аннотацию.

 @FXML
private void order(ActionEvent event)
 

Убедитесь, что этот класс Controller содержит этот метод.

Комментарии:

1. К сожалению, я все еще получаю ошибку. Это должно что-то делать с Order.fxml, так как переключение на другие сцены с помощью кнопки работает отлично. Я даже удалил кнопки и их методы в файле Order.fxml, чтобы посмотреть, сработает ли это тогда, но этого не произошло.