"Location not set"

Answered

IntelliJ 2022.2.3, JDK 17, Linux Mint Vanessa

I have a JavaFX project that uses multiple stages. In response to a context menu click event, I'm trying to load a second stage. When I attempt to load the FXML file, an exception "Location not set" is thrown. I've read that this indicates that the FXML file cannot be located.

Here's the project structure:

And here's the event handler code fragment that's attempting to load the form.

Stage stage = new Stage();
stage.setTitle("Form One");

Parent root = null;
AnotherFormController controller = null;
FXMLLoader loader = null;

try
{
URL url = getClass().getResource("FormOneLayout.fxml");
loader = new FXMLLoader(getClass().getResource("FormOneLayout.fxml"));
root = loader.load();
controller = loader.getController();
}
catch (Exception e)
{
System.err.println(e.getMessage());
return;
}

I have another, similar project created a few weeks ago that does much the same thing, except that it does not throw the exception - it loads the fxml and shows the stage. The code in both projects is identical (except for the FXML file name, of course).

I've added the URL url ... line to see what the path to the file is and it is the correct path to the file which exists in the target directory. Yet, when I step into the loader.load() method, it sees the path as null.

I can't help but think I'm missing something really simple. Can someone point out what I'm doing wrong?

I've attached the project. 2022_11_20_SAk6UZFaQ5XVoknUUPzViN

0
3 comments

Hi and thanks for the demo project.

Looks like the actual FormOneLayout.fxml file is missing from the resources folder. If I add it there, the app works:

0

Hi Arina.

Thanks for pointing out the very obvious error that I just couldn't see. I figured it would be something like that - sometimes a second pair of eyes is all it takes.

I'm having the same issue in a much more involved program. I guess I'll have to submit another case to upload that project. Hopefully you'll be able to point to the solution there.

Thanks!

    Sean

0
Happy to help Sean👍
Yes, feel free to submit it here or via 'Help | Contact Support'.
You can upload your project privately to https://uploads.jetbrains.com and provide the upload id.
0

Please sign in to leave a comment.