So I'm coding this chat-client for a school project, and now I need to implement a GUI, using JavaFX. I've built a neat looking GUI in Scene Builder. Whenever the client recieves a message it should now call a method in the controller to append the recived string to a TextField.
However, when I try to load the controller from the FXML-file I get this error:
null/../../../../img/jim.png
javafx.fxml.LoadException:
unknown path:16
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2579)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2425)
at com.example.main.GUI.start(GUI.java:46)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$163(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$176(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$174(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$149(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)Caused by: java.lang.IllegalArgumentException: Invalid URL: Invalid URL or resource not found
at javafx.scene.image.Image.validateUrl(Image.java:1100)
at javafx.scene.image.Image.<init>(Image.java:681)
at com.sun.javafx.fxml.builder.JavaFXImageBuilder.build(JavaFXImageBuilder.java:47)
at com.sun.javafx.fxml.builder.JavaFXImageBuilder.build(JavaFXImageBuilder.java:37)
at javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:763)
at javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2823)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2532)
... 11 moreCaused by: java.lang.IllegalArgumentException: Invalid URL or resource not found
at javafx.scene.image.Image.validateUrl(Image.java:1092)
... 17 more
Here's my code for getting the controller and calling a method in it:
try {
FXMLLoader loader = new FXMLLoader();
Pane p = loader.load(getClass().getResource("ChatForm.fxml").openStream());
ChatForm chatForm = (ChatForm) loader.getController();
chatForm.test();
} catch (IOException e) {
e.printStackTrace();
}
Finally, my FXML file:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane prefHeight="410.0" prefWidth="300.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.main.ChatForm">
<children>
<VBox prefHeight="410.0" prefWidth="300.0">
<children>
<ImageView fitHeight="135.0" fitWidth="300.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../../../../img/jim.png" />
</image>
</ImageView>
<TextArea fx:id="chatTextArea" editable="false" focusTraversable="false" prefHeight="232.0" prefWidth="300.0" wrapText="true" />
<TextField fx:id="messageTextField" />
<Label text="Skriv ".disconnect" för att logga ut">
<font>
<Font size="10.0" />
</font>
</Label>
</children>
</VBox>
Clearly something strange is up when loading the logo-image. Any ideas?
Happy new year's!