首页 \ 问答 \ JavaFX异常加载FXML文件(JavaFX exception loading FXML file)

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();
}

包浏览器中的项目如下所示:

https://image.ibb.co/ihGMoS/Capture.png (无法发布图片)

我从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
更新时间:2023-05-18 19:05

最满意答案

前两个示例表示strings ,最后一个示例表示JSON上a boolean值( http://www.json.org/

从规格:

值可以是string in double quotesstring in double quotes number ,或truefalsenull ,或an objectan array 。 这些结构可以嵌套

如果你真的想要a boolean那么使用最后一个例子。

JSON:API没有说明任何内容,因为规范本身是在JSON之上(继承所有JSON规范)


The first two examples represent strings and the last example represents a boolean value on JSON (http://www.json.org/)

From the spec:

A value can be a string in double quotes, or a number, or true or false or null, or an object or an 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 of JSON (inherit all the JSON 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 ...
  • 我用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 .
  • 前两个示例表示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 ...
  • 这是通过服务器端过滤器解决的,更新后的代码如下。 let parameters = [ "auth_token" : "test", "filter" : [ "phone-number" : self.PhoneNumber! ] ] Alamofire.request(.GET, url, parameters: parameters, encoding: .URL) .responseJSON { (res ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)