简体   繁体   中英

Scene Builder JavaFX Error opening FXML file

I am making one project and designing the FXML but on one point I got stuck with this error

Error for the path:

1

I don't know how to configure it

My FXMLMain.fxml code is:

    <center>
    <Pane fx:id="pneDashboard" prefHeight="320.0" prefWidth="800.0">
        <children>
            <fx:include source="/javafxapplication1/TempratureTab/FXMLTempraturetab.fxml" />
        </children>
    </Pane>
</center>

This is the main error description:

Caused by: java.io.FileNotFoundException: javafxapplication1\\TempratureTab\\FXMLTempraturetab.fxml (The system cannot find the path specified)

my package structure is

|--->source package

   |--->javafxapplication1

         |--->FXMLMain.fxml

         |--->TempratureTab(folder)

               |--->FXMLtempraturetab.fxml
                  

If anyone could help me with this

I have even tried it on different OS and different Netbeans IDE versions

And the interesting fact is that it executes perfectly...

In edit mode it shows no error on that line..

only in SceneBuilder.

According to this (bold is mine):

The <fx:include> tag creates an object from FXML markup defined in another file. It is used as follows <fx:include source="filename"/> where filename is the name of the FXML file to include. Values that begin with a leading slash character are treated as relative to the classpath . Values with no leading slash are considered relative to the path of the current document.

When you run the application, your project is obviously in the class path, and this:

<fx:include source="/javafxapplication1/TempratureTab/FXMLTempraturetab.fxml" />

will be resolved to a valid URL:

"file:/<full-path-of-your-project>/javafxapplication1/TempratureTab/FXMLTempraturetab.fxml"

But when you open the FXML with Scene Builder, it doesn't know about your project, so it can't add it to the classpath. Trying the absolute path will throw a java.io.FileNotFoundException , since the FXMLLoader can't find the file, as it resolves that path as:

"file:javafxapplication1/TempratureTab/FXMLTempraturetab.fxml"

which is not a valid URL.

While both relative and absolute path work when running the application, in order to open your FXML file from Scene Builder, you have to use a relative path:

<fx:include source="TempratureTab/FXMLTempraturetab.fxml" />

I had same problem and after hours of trial and errors here what worked for me:

  • IntelliJ 2020.1, JFX 15 + OpenJDK 15, Gradle 6.7, SceneBuilder 11.0

  • I made a Gradle project

  • I tried a basic package configuration: 在此处输入图片说明

  • At first, when clicking on the z.fxml "SceneBuilder" tab it was throwing: java.io.FileNotFoundException

  • I used Gradle [build] as my Configuration

  • Tried again the SceneBuilder tab: now working. Looks like (I guess) [build] updated the classpath (maybe it sounds obvious, I'm new to Gradle and build tools so that's why I haven't tried to use [build] earlier)

  • Apart from the above, I continually experience that it doesn't work when I use SceneBuilder as a standalone to import FXML files (maybe a bug?)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM