Scene Builder无法打开FXML文件问题求助
Hey there, let's break down why your FXML file works in the JVM but won't open in Scene Builder, plus fix your specific issue and help your teammate too.
1. Your FXML Has a Critical XML Syntax Error
Looking at your provided FXML code, the <ImageView> tag is not properly closed, and you've incorrectly nested the <Button> inside it. Here's the problematic section:
<ImageView fitHeight="112.0" fitWidth="112.0" layoutX="72.0" layoutY="46.0"> <Button layoutX="1159.0" layoutY="46.0" mnemonicParsing="false" onAction="#backButtonPressed" prefHeight="35.0" prefWidth="86.0" text="Back"> <!-- ... button content ... --> </Button>
JavaFX's runtime loader has some fault tolerance for minor XML issues, but Scene Builder's FXOMLoader (seen in your error stack trace) requires strict, well-formed XML to load the file for editing.
Fixed FXML Code
Here's the corrected version with proper tag closure and structure:
<?xml version="1.0" encoding="UTF-8"?> <?import com.jfoenix.controls.JFXCheckBox?> <?import com.jfoenix.controls.JFXTextField?> <?import javafx.scene.control.Button?> <?import javafx.scene.image.Image?> <?import javafx.scene.image.ImageView?> <?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.text.Font?> <AnchorPane prefHeight="600.0" prefWidth="1300.0" xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="smartdocClient.controller.CreateDoctorController"> <children> <!-- ImageView now properly closed --> <ImageView fitHeight="112.0" fitWidth="112.0" layoutX="72.0" layoutY="46.0" /> <Button layoutX="1159.0" layoutY="46.0" mnemonicParsing="false" onAction="#backButtonPressed" prefHeight="35.0" prefWidth="86.0" text="Back"> <font> <Font size="16.0" /> </font> </Button> <JFXTextField layoutX="254.0" layoutY="339.0" promptText="Phone Number" fx:id="phoneNo"/> </children> </AnchorPane>
2. Why Your Teammate's Files Are Failing
The same logic applies to your friend's problematic files: they likely have hidden XML syntax issues like:
- Unclosed tags (like your ImageView)
- Incorrectly nested elements
- Typos in XML attributes or namespace declarations
- Missing closing quotes for attributes
To diagnose these quickly:
- Use your IDE's built-in XML validation (most IDEs like IntelliJ/Eclipse will flag syntax errors in FXML)
- Run the FXML through a basic XML validator to catch well-formedness issues
3. Why JVM Runs It But Scene Builder Doesn't
JavaFX's runtime FXMLLoader is designed to be somewhat forgiving for common developer mistakes (like unclosed tags) to avoid breaking running applications. However, Scene Builder uses FXOMLoader which is a stricter parser focused on editing—it needs perfectly valid XML to build the visual tree for the editor interface. The error stack trace you provided confirms this: the crash happens directly in FXOMLoader.load().
内容的提问来源于stack exchange,提问作者Skorejen

