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 r
The syntax url="@..." in your FXML file refers to a path relative to the current FXMLLoader
's location property.
However, when you load the FXML file, you are not providing the FXMLLoader
with a location, but an input stream. Thus the location is null
and (as seen in the stack trace), your path gets interpreted as
null/../../../../img/jim.png
To fix this, provide the location to the FXMLLoader
, instead of the input stream:
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("ChatForm.fxml"));
Pane p = loader.load();
ChatForm chatForm = (ChatForm) loader.getController();
chatForm.test();
} catch (IOException e) {
e.printStackTrace();
}
This will fix the immediate problem, assuming the path is actually correct. I think you still have other, essentially unrelated, problems, as you never seem to do anything with the scene graph you load (i.e. you never display the pane p
).