1

I am trying to load an XML Resource, and I am doing it like this:

fxmlLoader = new FXMLLoader();
root = fxmlLoader.load(getClass().getResource("Document.fxml").openStream());

When I run my code I then get this error:

null/../css/button.css
javafx.fxml.LoadException: 
unknown path:23

When I look at line 23 I have this:

<URL value="@../css/button.css" />

this works:

fxmlLoader = new FXMLLoader();
root = fxmlLoader.load(getClass().getResource("Document.fxml"));

but then when I run the following

controller = (DocumentController)fxmlLoader.getController();

controller is null

How can I fix the css issue?

2
  • Do you have the fx:controller defined in your Document.fxml ? Commented Jul 2, 2014 at 6:48
  • Yes: <AnchorPane fx:id="anchorPane" minHeight="200.0" minWidth="200.0" prefHeight="600.0" prefWidth="1200.0" styleClass="anchor-pane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="phantom.DocumentController"> Commented Jul 2, 2014 at 13:53

2 Answers 2

4

This is a bit of a guess, but I think the issue is that you're providing an input stream to the FXMLLoader instead of a URL. Because of this, the FXMLLoader is unaware of the location of the FXML resource, and hence it can't resolve the .. in the URL tag. This would explain the error message:

null/../css/button.css

javafx.fxml.LoadException:

unknown path:23

The path you provided is relative to null because the FXMLLoader doesn't know the location of the FXML file; notice also it reports "unknown path" as the source of the FXML.

Try this (which is more common anyway)

fxmlLoader = new FXMLLoader(getClass().getResource("Document.fxml"));
root = fxmlLoader.load(); 

I'm figuring it returns null for the controller only because there was an error in loading the fxml.

Sign up to request clarification or add additional context in comments.

2 Comments

It seems that, that is the issue. It doesn't show null anymore!
The way I had it was from someone else's answer. Thanks for the Answer!
0

In your .fxml, change <URL value = "@../css/button.css"/> to <URL value = "@/css/button.css" />. It's the same if you had "css" or "image".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.