我开发了一个JavaFX应用程序,但我遇到了一个非常奇怪的错误。我想这与我的.FXML文件有关,但我不知道到底是什么。堆栈跟踪说它涉及Scene类的方法,它们与节点方向相关联。令人惊讶的是,我没有在.FXML文件中或其他任何地方操纵这个属性,因此我不知道为什么每次我点击负责打开用这个.FXML创建的新窗口的按钮时都会发生这个错误。 (由SceneBuilder生成)。
我很感激您在这件事上可以提供的所有帮助和想法。非常感谢你。
StackOverflowException:
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8411)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:380)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:294)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:416)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:415)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
Caused by: 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 sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
... 52 more
Caused by: java.lang.StackOverflowError
at javafx.scene.Scene.getWindow(Scene.java:623)
at javafx.scene.Scene.calcEffectiveNodeOrientation(Scene.java:6228)
at javafx.scene.Scene.getEffectiveNodeOrientation(Scene.java:6188)
at javafx.scene.Scene.calcEffectiveNodeOrientation(Scene.java:6240)
at javafx.scene.Scene.getEffectiveNodeOrientation(Scene.java:6188)
at javafx.scene.Scene.calcEffectiveNodeOrientation(Scene.java:6240)
at javafx.scene.Scene.getEffectiveNodeOrientation(Scene.java:6188)
at javafx.scene.Scene.calcEffectiveNodeOrientation(Scene.java:6240)
at javafx.scene.Scene.getEffectiveNodeOrientation(Scene.java:6188)
at javafx.scene.Scene.calcEffectiveNodeOrientation(Scene.java:6240)
at javafx.scene.Scene.getEffectiveNodeOrientation(Scene.java:6188)
at javafx.scene.Scene.calcEffectiveNodeOrientation(Scene.java:6240)
at javafx.scene.Scene.getEffectiveNodeOrientation(Scene.java:6188)
at javafx.scene.Scene.calcEffectiveNodeOrientation(Scene.java:6240)
at javafx.scene.Scene.getEffectiveNodeOrientation(Scene.java:6188)
at javafx.scene.Scene.calcEffectiveNodeOrientation(Scene.java:6240)
...
我的.FXML文件:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Accordion?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ButtonBar?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="pl.nombritech.Produktor.view.UstawieniaController">
<children>
<Label alignment="CENTER" maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308" text="Ustawienia">
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</Label>
<Accordion fx:id="accordion" maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308" VBox.vgrow="ALWAYS">
<panes>
<TitledPane fx:id="kategoriaTP" text="Kategoria">
<content>
<ScrollPane fitToHeight="true" fitToWidth="true"
maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
<content>
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
<children>
<ListView fx:id="kategoria_ListaLV" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</ListView>
<HBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
spacing="5.0" VBox.vgrow="NEVER">
<children>
<TextField fx:id="kategoria_NazwaTF" maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308" HBox.hgrow="ALWAYS" />
<Button fx:id="kategoria_DodajB" maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308" mnemonicParsing="false"
onAction="#handleKategoria_DodajB" text="Dodaj" />
<Button fx:id="kategoria_UsunB" maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308" mnemonicParsing="false"
onAction="#handleKategoria_UsunB" text="Usuń" />
</children>
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" />
</VBox.margin>
</HBox>
</children>
</VBox>
</content>
</ScrollPane>
</content>
</TitledPane>
<TitledPane text="Producent">
<content>
<ScrollPane fitToHeight="true" fitToWidth="true"
maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
<content>
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
<children>
<ListView fx:id="producent_ListaLV" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</ListView>
<HBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
spacing="5.0" VBox.vgrow="NEVER">
<children>
<TextField fx:id="producent_NazwaTF" maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308" HBox.hgrow="ALWAYS" />
<Button fx:id="producent_DodajB" maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308" mnemonicParsing="false"
onAction="#handleProducent_DodajB" text="Dodaj" />
<Button fx:id="producent_UsunB" maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308" mnemonicParsing="false"
onAction="#handleProducent_UsunB" text="Usuń" />
</children>
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" />
</VBox.margin>
</HBox>
</children>
</VBox>
</content>
</ScrollPane>
</content>
</TitledPane>
<TitledPane text="Sklep">
<content>
<ScrollPane fitToHeight="true" fitToWidth="true"
maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
<content>
<VBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
<children>
<ListView fx:id="sklep_ListaLV" maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308" VBox.vgrow="ALWAYS">
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</ListView>
<HBox maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
spacing="5.0" VBox.vgrow="NEVER">
<children>
<TextField fx:id="sklep_NazwaTF" maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308" HBox.hgrow="ALWAYS" />
<Button fx:id="sklep_DodajB" maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308" mnemonicParsing="false"
onAction="#handleSklep_DodajB" text="Dodaj" />
<Button fx:id="sklep_UsunB" maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308" mnemonicParsing="false"
onAction="#handleSklep_UsunB" text="Usuń" />
</children>
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" />
</VBox.margin>
</HBox>
</children>
</VBox>
</content>
</ScrollPane>
</content>
</TitledPane>
</panes>
</Accordion>
<ButtonBar maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
<buttons>
<Button fx:id="zamknijB" maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308" mnemonicParsing="false" onAction="#handleAnulujB"
text="Zamknij" />
</buttons>
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</ButtonBar>
</children>
</VBox>
编辑:单击按钮后用于打开新阶段的代码:
@FXML
private void handleUstawieniaB(ActionEvent e)
{
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/Ustawienia.fxml"));
Parent root = null;
try
{
root = loader.load();
}
catch (IOException e1)
{
e1.printStackTrace();
}
Stage stage = new Stage(StageStyle.DECORATED);
stage.setTitle("Produktor");
stage.initOwner(stage);
stage.initModality(Modality.WINDOW_MODAL);
Scene scena = new Scene(root);
stage.setScene(scena);
UstawieniaController controller = loader.getController();
controller.setStage(stage);
// a method used to set some initial data in the new window, it doesn't change anything if I turn it off, so i don't think it is meaningful here
controller.rozpocznij();
stage.showAndWait();
}
答案 0 :(得分:0)
在您设置的 Java 代码行中:
stage.initOwner(stage);
它会导致错误。您需要设置另一个舞台才能成为新舞台的所有者。您不能说 stage1
是 stage1
的所有者。
尝试创建另一个阶段或使用其他。