JavaFX异常加载FXML文件(JavaFX exception loading FXML file)
我一直在研究桌面应用程序,我需要使用JavaFX。 我在使用Scene Builder构建的eclipse上的JavaFX项目中创建了各种FXML文件。 除了这个讨厌的文件(FXMLImgList.fxml)外,我没有任何问题可以加载任何FXML文件。
主要想法是,当按下按钮时,会出现一个新窗口。 这是我为该按钮的事件处理程序的代码:
@FXML private void handleOnActionButtonImg(ActionEvent e) throws MalformedURLException, URISyntaxException { FXMLLoader loader = new FXMLLoader(getClass().getResource("/res/FXMLImgList.fxml").toURI().toURL()); VBox root = null; try { root = (VBox) loader.load(); // ERROR LOADING HERE } catch (IOException e1) { e1.printStackTrace(); } ImgListController ilc = loader.getController(); ilc.init(imgUrl); Scene scene = new Scene(root); Stage stage = new Stage(); stage.initModality(Modality.WINDOW_MODAL); stage.initOwner((Stage) vBox.getScene().getWindow()); stage.setScene(scene); stage.setResizable(false); stage.setTitle("Elegir imagen"); stage.show(); }
包浏览器中的项目如下所示:
我从try-catch块得到这个异常:
javafx.fxml.LoadException: /C:/Users/Ximo/Desktop/UNI/2017-2018%20(UPV)/IPC/EclipseWorkspaceIPC/PL03_Ej2/bin/res/FXMLImgList.fxml at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409) at application.VentanaController.handleOnActionButtonImg(VentanaController.java:108) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.reflect.misc.Trampoline.invoke(Unknown Source) at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.reflect.misc.MethodUtil.invoke(Unknown Source) at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769) 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.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:8413) 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.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:381) at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:417) at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389) at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416) 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$147(WinApplication.java:177) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.IllegalArgumentException: Invalid URL: unknown protocol: c at javafx.scene.image.Image.validateUrl(Image.java:1121) at javafx.scene.image.Image.<init>(Image.java:659) at application.ImgListController.initialize(ImgListController.java:64) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548) ... 61 more Caused by: java.net.MalformedURLException: unknown protocol: c at java.net.URL.<init>(Unknown Source) at java.net.URL.<init>(Unknown Source) at java.net.URL.<init>(Unknown Source) at javafx.scene.image.Image.validateUrl(Image.java:1115) ... 64 more 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.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:8413) 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.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:381) at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:417) at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389) at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416) 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$147(WinApplication.java:177) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.reflect.misc.Trampoline.invoke(Unknown Source) at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.reflect.misc.MethodUtil.invoke(Unknown Source) at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769) ... 48 more Caused by: java.lang.NullPointerException: Root cannot be null at javafx.scene.Scene.<init>(Scene.java:336) at javafx.scene.Scene.<init>(Scene.java:194) at application.VentanaController.handleOnActionButtonImg(VentanaController.java:116) ... 58 more
更奇怪的是,其余的FXML文件加载得很好,比如这个:
@FXML private void handleOnActionButtonMod(ActionEvent event) { FXMLLoader loader = new FXMLLoader(getClass().getResource("/res/FXMLVentana.fxml")); VBox root = null; try { root = (VBox) loader.load(); // NO ERROR LOADING HERE } catch (IOException e) { e.printStackTrace(); } VentanaController vac = loader.getController(); vac.init(observablePersonData, table.getSelectionModel().selectedIndexProperty().getValue()); Scene scene = new Scene(root); Stage stage = new Stage(); stage.initModality(Modality.WINDOW_MODAL); stage.initOwner(this.stage); stage.setScene(scene); stage.setResizable(false); stage.setTitle("Modificar"); stage.show(); }
这个事件处理程序背后的想法几乎是相同的, 按下按钮 - >窗口打开并工作得很好。 我已经尝试了很多,例如编辑返回的URL,但似乎没有任何工作。
我已经注意到第67行的消息:
引起:java.lang.IllegalArgumentException:无效的URL:未知的协议:c
但是结果如下:
System.out.println(getClass().getResource("/res/FXMLVentana.fxml")); System.out.println(getClass().getResource("/res/FXMLImgList.fxml"));
输出:
文件:/ C:/用户/细末/桌面/ UNI / 2017年至2018年20%(UPV)/IPC/EclipseWorkspaceIPC/PL03_Ej2/bin/res/FXMLVentana.fxml
文件:/ C:/用户/细末/桌面/ UNI / 2017年至2018年20%(UPV)/IPC/EclipseWorkspaceIPC/PL03_Ej2/bin/res/FXMLImgList.fxml
以下是FXMLImgList.fxml的代码:
<?import javafx.geometry.Insets?> <?import javafx.scene.control.Button?> <?import javafx.scene.layout.HBox?> <?import javafx.scene.layout.VBox?> <VBox fx:id="root" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" spacing="12.0" xmlns=" http://javafx.com/javafx/8.0.151" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.ImgListController"> <children> <HBox alignment="CENTER_RIGHT" spacing="12.0"> <children> <Button fx:id="cancelar" mnemonicParsing="false" onAction="#handleOnActionButtonCancelar" text="Cancelar" /> <Button fx:id="salvar" mnemonicParsing="false" onAction="#handleOnActionButtonSalvar" text="Salvar" /> </children> <VBox.margin> <Insets /> </VBox.margin> </HBox> </children> <padding> <Insets bottom="12.0" left="12.0" right="12.0" top="12.0" /> </padding> </VBox>
这里是FXMLVentana.fxml:
<?xml version="1.0" encoding="UTF-8"?> <?import javafx.geometry.Insets?> <?import javafx.scene.control.Button?> <?import javafx.scene.control.Label?> <?import javafx.scene.control.TextField?> <?import javafx.scene.image.ImageView?> <?import javafx.scene.layout.HBox?> <?import javafx.scene.layout.VBox?> <VBox fx:id="vBox" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" spacing="12.0" xmlns="http://javafx.com/javafx/8.0.151" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.VentanaController"> <children> <HBox alignment="CENTER" spacing="30.0"> <children> <Label prefHeight="17.0" prefWidth="53.0" text="DNI" /> <TextField fx:id="dni" /> </children> </HBox> <HBox alignment="CENTER" spacing="30.0"> <children> <Label prefHeight="17.0" prefWidth="53.0" text="Nombre" /> <TextField fx:id="nombre" /> </children> </HBox> <HBox alignment="CENTER" spacing="30.0"> <children> <Label prefHeight="17.0" prefWidth="52.0" text="Apellidos" /> <TextField fx:id="apellidos" /> </children> </HBox> <HBox alignment="CENTER" spacing="30.0"> <children> <Label prefHeight="17.0" prefWidth="52.0" text="Ciudad" /> <TextField fx:id="city" /> </children> </HBox> <HBox alignment="CENTER" spacing="30.0"> <children> <Label prefHeight="17.0" prefWidth="52.0" text="Provincia" /> <TextField fx:id="province" /> </children> </HBox> <HBox alignment="CENTER" spacing="12.0"> <children> <ImageView fx:id="imgView" fitHeight="80.0" fitWidth="80.0" onMouseClicked="#handleImgMouseClick" pickOnBounds="true" preserveRatio ="true" /> <Button fx:id="buttonImg" mnemonicParsing="false" onAction="#handleOnActionButtonImg" text="Imagen" /> </children > </HBox > < HBox alignment="CENTER_RIGHT" spacing="12.0"> <children> <Button fx:id="buttonCancelar" mnemonicParsing="false" onAction="#handleOnActionButtonCancelar" text="Cancelar" /> <Button fx:id="buttonAction" mnemonicParsing="false" onAction="#handleOnActionButtonAction" text="Salvar" /> </children> </HBox> </children> <padding> <Insets bottom="12.0" left="30.0" right="30.0" top="12.0" /> </padding> </VBox>
总而言之,我全都没有想法,也没有发现我似乎解决了这个问题。 任何帮助表示赞赏,谢谢!
I have been working on a desktop application, where I need to use JavaFX. I have created various FXML files in a JavaFX project on eclipse built with Scene Builder. I have no issues loading any FXML file except for this one pesky file (FXMLImgList.fxml).
The main idea is that when a button is pressed, a new window appears. Here is my code for the event handler for that button:
@FXML private void handleOnActionButtonImg(ActionEvent e) throws MalformedURLException, URISyntaxException { FXMLLoader loader = new FXMLLoader(getClass().getResource("/res/FXMLImgList.fxml").toURI().toURL()); VBox root = null; try { root = (VBox) loader.load(); // ERROR LOADING HERE } catch (IOException e1) { e1.printStackTrace(); } ImgListController ilc = loader.getController(); ilc.init(imgUrl); Scene scene = new Scene(root); Stage stage = new Stage(); stage.initModality(Modality.WINDOW_MODAL); stage.initOwner((Stage) vBox.getScene().getWindow()); stage.setScene(scene); stage.setResizable(false); stage.setTitle("Elegir imagen"); stage.show(); }
The project in the package explorer looks like so:
https://image.ibb.co/ihGMoS/Capture.png (Can't post images)
I get this exception from the try-catch block:
javafx.fxml.LoadException: /C:/Users/Ximo/Desktop/UNI/2017-2018%20(UPV)/IPC/EclipseWorkspaceIPC/PL03_Ej2/bin/res/FXMLImgList.fxml at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409) at application.VentanaController.handleOnActionButtonImg(VentanaController.java:108) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.reflect.misc.Trampoline.invoke(Unknown Source) at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.reflect.misc.MethodUtil.invoke(Unknown Source) at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769) 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.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:8413) 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.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:381) at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:417) at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389) at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416) 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$147(WinApplication.java:177) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.IllegalArgumentException: Invalid URL: unknown protocol: c at javafx.scene.image.Image.validateUrl(Image.java:1121) at javafx.scene.image.Image.<init>(Image.java:659) at application.ImgListController.initialize(ImgListController.java:64) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548) ... 61 more Caused by: java.net.MalformedURLException: unknown protocol: c at java.net.URL.<init>(Unknown Source) at java.net.URL.<init>(Unknown Source) at java.net.URL.<init>(Unknown Source) at javafx.scene.image.Image.validateUrl(Image.java:1115) ... 64 more 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.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:8413) 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.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:381) at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$353(GlassViewEventHandler.java:417) at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389) at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416) 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$147(WinApplication.java:177) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.reflect.misc.Trampoline.invoke(Unknown Source) at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.reflect.misc.MethodUtil.invoke(Unknown Source) at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769) ... 48 more Caused by: java.lang.NullPointerException: Root cannot be null at javafx.scene.Scene.<init>(Scene.java:336) at javafx.scene.Scene.<init>(Scene.java:194) at application.VentanaController.handleOnActionButtonImg(VentanaController.java:116) ... 58 more
What's even stranger, the rest of the FXML files load just fine, for example this one:
@FXML private void handleOnActionButtonMod(ActionEvent event) { FXMLLoader loader = new FXMLLoader(getClass().getResource("/res/FXMLVentana.fxml")); VBox root = null; try { root = (VBox) loader.load(); // NO ERROR LOADING HERE } catch (IOException e) { e.printStackTrace(); } VentanaController vac = loader.getController(); vac.init(observablePersonData, table.getSelectionModel().selectedIndexProperty().getValue()); Scene scene = new Scene(root); Stage stage = new Stage(); stage.initModality(Modality.WINDOW_MODAL); stage.initOwner(this.stage); stage.setScene(scene); stage.setResizable(false); stage.setTitle("Modificar"); stage.show(); }
The idea behind this event handler is pretty much the same, press button -> window opens and works just fine. I've tried many this like editing the returned URL but nothing seems to work.
I've notice the message on line 67:
Caused by: java.lang.IllegalArgumentException: Invalid URL: unknown protocol: c
However the result of:
System.out.println(getClass().getResource("/res/FXMLVentana.fxml")); System.out.println(getClass().getResource("/res/FXMLImgList.fxml"));
Outputs:
file:/C:/Users/Ximo/Desktop/UNI/2017-2018%20(UPV)/IPC/EclipseWorkspaceIPC/PL03_Ej2/bin/res/FXMLVentana.fxml
file:/C:/Users/Ximo/Desktop/UNI/2017-2018%20(UPV)/IPC/EclipseWorkspaceIPC/PL03_Ej2/bin/res/FXMLImgList.fxml
Here's the code for FXMLImgList.fxml:
<?import javafx.geometry.Insets?> <?import javafx.scene.control.Button?> <?import javafx.scene.layout.HBox?> <?import javafx.scene.layout.VBox?> <VBox fx:id="root" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" spacing="12.0" xmlns=" http://javafx.com/javafx/8.0.151" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.ImgListController"> <children> <HBox alignment="CENTER_RIGHT" spacing="12.0"> <children> <Button fx:id="cancelar" mnemonicParsing="false" onAction="#handleOnActionButtonCancelar" text="Cancelar" /> <Button fx:id="salvar" mnemonicParsing="false" onAction="#handleOnActionButtonSalvar" text="Salvar" /> </children> <VBox.margin> <Insets /> </VBox.margin> </HBox> </children> <padding> <Insets bottom="12.0" left="12.0" right="12.0" top="12.0" /> </padding> </VBox>
And here's FXMLVentana.fxml:
<?xml version="1.0" encoding="UTF-8"?> <?import javafx.geometry.Insets?> <?import javafx.scene.control.Button?> <?import javafx.scene.control.Label?> <?import javafx.scene.control.TextField?> <?import javafx.scene.image.ImageView?> <?import javafx.scene.layout.HBox?> <?import javafx.scene.layout.VBox?> <VBox fx:id="vBox" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" spacing="12.0" xmlns="http://javafx.com/javafx/8.0.151" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.VentanaController"> <children> <HBox alignment="CENTER" spacing="30.0"> <children> <Label prefHeight="17.0" prefWidth="53.0" text="DNI" /> <TextField fx:id="dni" /> </children> </HBox> <HBox alignment="CENTER" spacing="30.0"> <children> <Label prefHeight="17.0" prefWidth="53.0" text="Nombre" /> <TextField fx:id="nombre" /> </children> </HBox> <HBox alignment="CENTER" spacing="30.0"> <children> <Label prefHeight="17.0" prefWidth="52.0" text="Apellidos" /> <TextField fx:id="apellidos" /> </children> </HBox> <HBox alignment="CENTER" spacing="30.0"> <children> <Label prefHeight="17.0" prefWidth="52.0" text="Ciudad" /> <TextField fx:id="city" /> </children> </HBox> <HBox alignment="CENTER" spacing="30.0"> <children> <Label prefHeight="17.0" prefWidth="52.0" text="Provincia" /> <TextField fx:id="province" /> </children> </HBox> <HBox alignment="CENTER" spacing="12.0"> <children> <ImageView fx:id="imgView" fitHeight="80.0" fitWidth="80.0" onMouseClicked="#handleImgMouseClick" pickOnBounds="true" preserveRatio ="true" /> <Button fx:id="buttonImg" mnemonicParsing="false" onAction="#handleOnActionButtonImg" text="Imagen" /> </children > </HBox > < HBox alignment="CENTER_RIGHT" spacing="12.0"> <children> <Button fx:id="buttonCancelar" mnemonicParsing="false" onAction="#handleOnActionButtonCancelar" text="Cancelar" /> <Button fx:id="buttonAction" mnemonicParsing="false" onAction="#handleOnActionButtonAction" text="Salvar" /> </children> </HBox> </children> <padding> <Insets bottom="12.0" left="30.0" right="30.0" top="12.0" /> </padding> </VBox>
In conclusion, I'm all out of ideas and nothing I find onlince seems to solve the issue. Any help is appreciated, thanks!
原文:https://stackoverflow.com/questions/49141021
最满意答案
前两个示例表示
strings
,最后一个示例表示JSON上a boolean
值( http://www.json.org/ )从规格:
值可以是
string in double quotes
的string in double quotes
number
,或true
或false
或null
,或an object
或an array
。 这些结构可以嵌套如果你真的想要
a boolean
那么使用最后一个例子。
JSON:API
没有说明任何内容,因为规范本身是在JSON
之上(继承所有JSON
规范)The first two examples represent
strings
and the last example representsa boolean
value on JSON (http://www.json.org/)From the spec:
A value can be a
string in double quotes
, or anumber
, ortrue
orfalse
ornull
, oran object
oran array
. These structures can be nested.`If you really want
a boolean
then use the last example.
JSON:API
do not say anything about it because, the specification itself is on top ofJSON
(inherit all theJSON
specification)
相关问答
更多-
Ember-data目前不支持你想要的内容。 因此,ember-data不会将关系数据保存在保存的有效载荷中。 但它可能通过使用自定义适配器和序列化器来完成您自己的操作。 我强烈建议您检出API ,然后查看源代码。 如果您在模型上调用.save() ,则在适配器上createRecord方法。 这里调用serializeIntoHash的serializeIntoHash来序列化模型。 serializeIntoHash调用serialize ,其中serializeBelongsTo和serializeH ...
-
JSON:API规范解释了关系数据应该如何。 您要求的实际上是嵌套的,或者更好的是“包含”按照规范。 我建议你在那里阅读http://jsonapi.org/format/#document-compound-documents ,了解有关包含/嵌套关系的规范的更多细节 另外,关于你的问题,你需要告诉序列化器渲染包含的元素,如下所示: render @posts, include: ['authors', 'comments']有关详细信息,请参阅此处: https : //github.com/rails ...
-
没有值的属性在HTML中有效,但在XHTML中无效,因为它在XML中是不允许的。 也许这就是你的困惑所在。 那么,哪一个有效取决于您的文档的doctype。 Attribues without values are valid in HTML, but invalid in XHTML, because it's not allowed in XML. Perhaps that's where your confusion is coming from. So, which one is valid dep ...
-
JTidy和布尔属性(JTidy and boolean attributes)[2022-01-18]
我用JSoup层修复了它,只需将HTML读取到JSoup并将其打印成字符串。 JTidy无法解析它,但有端口tidy-html5可以使用它,但我不能使用它。 I've fixed it with JSoup layer, just read html to JSoup and print it out to string. JTidy cannot parse it, but there is port tidy-html5 may work with it, but I cannot use it . -
JSONAPI布尔属性(JSONAPI boolean attributes)[2023-08-08]
前两个示例表示strings ,最后一个示例表示JSON上a boolean值( http://www.json.org/ ) 从规格: 值可以是string in double quotes的string in double quotes number ,或true或false或null ,或an object或an array 。 这些结构可以嵌套 如果你真的想要a boolean那么使用最后一个例子。 JSON:API没有说明任何内容,因为规范本身是在JSON之上(继承所有JSON规范) The fi ... -
看来你正在使用0.2版本的JSONAPI.NET,它是NuGet上的最新版本。 不幸的是,这个版本已经过时了,并且不符合当前版本的JSON API。 master上的版本非常接近规范,尽管我没有时间对其进行修改并发布。 这里有一些粗略的文档。 It seems you are using the 0.2.0 version of JSONAPI.NET which is the latest on NuGet. Unfortunately this version is quite out of date ...
-
你的代码看起来还不错。 但它可以简化 - var b bytes.Buffer // you could use buffer pool here err := jsonapi.MarshalManyPayload(&b, albumList()) if err != nil { return err } return c.JSONBlob(http.StatusOK, b.Bytes()) 遵循您的想法: 方法1 - c.Response().Header().Set(echo.HeaderCo ...
-
我目前通过使用自定义org.hibernate.dialect.Dialect以特定于Hibernate的方式解决它: public class MySqlDialect extends MySQL57InnoDBDialect { public MySqlDialect() { registerColumnType(Types.BOOLEAN, "boolean"); } } 我用Spring Boot属性注册了它: spring.jpa.database-platfor ...
-
根据与@Gerrat的讨论,在一些误解后更新答案 当然第二种方式更好。 第一个表是First Normal Form,因为它的域(字段值)都没有任何集合作为元素(具有多值的列)。 但问题在于重复的列(在表中重复作为列的品牌只是在商场中标记),这样的设计通常被认为是反模式,但是因为它将表限制为预定的固定数量的值并且因为它强制为每个列重复查询和其他业务逻辑。 换句话说,它违反了“ DRY ”设计原则。 始终尽量使您的数据库易于维护和规范化。 参考文献: https://en.wikipedia.org/wiki ...
-
Alamofire和JSONAPI(Alamofire and JSONAPI)[2022-10-04]
这是通过服务器端过滤器解决的,更新后的代码如下。 let parameters = [ "auth_token" : "test", "filter" : [ "phone-number" : self.PhoneNumber! ] ] Alamofire.request(.GET, url, parameters: parameters, encoding: .URL) .responseJSON { (res ...