我使用Scene Builder构建了一个场景,但在尝试使用FXMLLoader打开fxml文件时出现了一些错误。我的JavaFX版本是2.2.55-b13。这是我的fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.collections.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?>
<BorderPane xmlns="http://javafx.com/javafx/2.2" xmlns:fx="http://javafx.com/fxml/1" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="800.0" fx:controller="org.impactvolunteers.management.gui.CreateVolunteerController">
<center>
<VBox prefHeight="200.0" prefWidth="100.0">
<children>
<Label text="Create new volunteer" />
<Separator prefWidth="200.0">
<VBox.margin>
<Insets bottom="10.0" top="10.0" />
</VBox.margin>
</Separator>
<GridPane prefHeight="116.0" prefWidth="760.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="10.0" minWidth="10.0" prefWidth="10.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Name:" />
<Label text="Birthday:" GridPane.rowIndex="1" />
<Label text="Phone:" GridPane.rowIndex="2" />
<Label text="Email:" GridPane.rowIndex="3" />
<Label text="City:" GridPane.columnIndex="3" GridPane.rowIndex="2" />
<Label text="Country:" GridPane.columnIndex="3" GridPane.rowIndex="3" />
<TextField fx:id="name" GridPane.columnIndex="1" />
<TextField fx:id="birthday" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField fx:id="phone" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<TextField fx:id="email" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<TextField fx:id="city" GridPane.columnIndex="4" GridPane.rowIndex="2" />
<Button maxWidth="180.0" minWidth="180.0" mnemonicParsing="false" onAction="#onSaveClicked" prefWidth="180.0" text="Save" GridPane.columnIndex="4" />
<Button maxWidth="180.0" minWidth="180.0" mnemonicParsing="false" onAction="#onBackClicked" prefWidth="180.0" text="Back" GridPane.columnIndex="3" />
<ChoiceBox fx:id="country" prefWidth="150.0" GridPane.columnIndex="4" GridPane.rowIndex="3" />
</children>
</GridPane>
<GridPane>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="160.0" minWidth="160.0" prefWidth="160.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="150.0" minWidth="150.0" prefWidth="150.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="30.0" minHeight="30.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="50.0" minHeight="50.0" prefHeight="50.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="10.0" minHeight="10.0" prefHeight="10.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="50.0" minHeight="50.0" prefHeight="50.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="10.0" minHeight="10.0" prefHeight="10.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="50.0" minHeight="50.0" prefHeight="50.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<TextArea fx:id="qualifications" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextArea fx:id="workexperience" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<TextArea fx:id="interests" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="5" />
<Label text="Degrees/Qualifications:" GridPane.rowIndex="1" />
<Label text="Work Experience:" GridPane.rowIndex="3" />
<Label text="Interests:" GridPane.rowIndex="5" />
</children>
</GridPane>
<GridPane>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="160.0" minWidth="160.0" prefWidth="160.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="40.0" minHeight="40.0" prefHeight="40.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="40.0" minHeight="40.0" prefHeight="40.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Preferred Beneficiaries:" GridPane.rowIndex="1" />
<Label text="Regions:" GridPane.rowIndex="2" />
<CheckBox mnemonicParsing="false" text="CheckBox" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<CheckBox mnemonicParsing="false" text="CheckBox" GridPane.columnIndex="1" GridPane.rowIndex="2" />
</children>
</GridPane>
<GridPane>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="100.0" minWidth="100.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="10.0" minHeight="10.0" prefHeight="10.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="150.0" minHeight="150.0" prefHeight="150.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="10.0" minHeight="10.0" prefHeight="10.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="150.0" minHeight="150.0" prefHeight="150.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="Availability:" GridPane.rowIndex="1" />
<Label text="Skills:" GridPane.rowIndex="3" />
<TableView prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="1">
<columns>
<TableColumn prefWidth="75.0" text="C1" />
<TableColumn prefWidth="75.0" text="C2" />
</columns>
</TableView>
<TableView prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="3">
<columns>
<TableColumn prefWidth="75.0" text="C1" />
<TableColumn prefWidth="75.0" text="C2" />
</columns>
</TableView>
</children>
</GridPane>
</children>
<opaqueInsets>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</opaqueInsets>
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</padding>
</VBox>
</center>
</BorderPane>
堆栈跟踪:
Invalid property.
/home/kennelcrash/Semester%204/SEPM%20PR/qse-sepm-ss14-08/VolunteerAdmin/target/classes/fxml/CreateVolunteer.fxml:14
at javafx.fxml.FXMLLoader$PropertyElement.<init>(FXMLLoader.java:1169)
at javafx.fxml.FXMLLoader.createElement(FXMLLoader.java:2380)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2353)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2172)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2069)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2830)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2809)
at org.impactvolunteers.management.FXMLSpringLoader.load(FXMLSpringLoader.java:86)
at org.impactvolunteers.management.FXMLSpringLoader.load(FXMLSpringLoader.java:71)
at org.impactvolunteers.management.gui.Screen.init(Screen.java:40)
at org.impactvolunteers.management.gui.ScreensController.init(ScreensController.java:39)
at org.impactvolunteers.management.gui.MainController.initialize(MainController.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:75)
at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:279)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2223)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2069)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2830)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2809)
at org.impactvolunteers.management.FXMLSpringLoader.load(FXMLSpringLoader.java:86)
at org.impactvolunteers.management.FXMLSpringLoader.load(FXMLSpringLoader.java:71)
at org.impactvolunteers.management.App.start(App.java:32)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:219)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:182)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:179)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication$3$1.run(GtkApplication.java:89)
at java.lang.Thread.run(Thread.java:745)
java.lang.reflect.InvocationTargetException
/home/kennelcrash/Semester%204/SEPM%20PR/qse-sepm-ss14-08/VolunteerAdmin/target/classes/fxml/MainApplication.fxml
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2228)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2069)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2830)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2809)
at org.impactvolunteers.management.FXMLSpringLoader.load(FXMLSpringLoader.java:86)
at org.impactvolunteers.management.FXMLSpringLoader.load(FXMLSpringLoader.java:71)
at org.impactvolunteers.management.App.start(App.java:32)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:219)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:182)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:179)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication$3$1.run(GtkApplication.java:89)
at java.lang.Thread.run(Thread.java:745)
Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Thread.java:745)
Caused by: javafx.fxml.LoadException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2228)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2069)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2830)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2809)
at org.impactvolunteers.management.FXMLSpringLoader.load(FXMLSpringLoader.java:86)
at org.impactvolunteers.management.FXMLSpringLoader.load(FXMLSpringLoader.java:71)
at org.impactvolunteers.management.App.start(App.java:32)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:219)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:182)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:179)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication$3$1.run(GtkApplication.java:89)
... 1 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:75)
at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:279)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2223)
... 16 more
Caused by: javafx.fxml.LoadException: Invalid property.
at javafx.fxml.FXMLLoader$PropertyElement.<init>(FXMLLoader.java:1169)
at javafx.fxml.FXMLLoader.createElement(FXMLLoader.java:2380)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2353)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2172)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2069)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2830)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2809)
at org.impactvolunteers.management.FXMLSpringLoader.load(FXMLSpringLoader.java:86)
at org.impactvolunteers.management.FXMLSpringLoader.load(FXMLSpringLoader.java:71)
at org.impactvolunteers.management.gui.Screen.init(Screen.java:40)
at org.impactvolunteers.management.gui.ScreensController.init(ScreensController.java:39)
at org.impactvolunteers.management.gui.MainController.initialize(MainController.java:26)
... 26 more
指定的行对我来说没问题,我在其他fxml文件中使用了一些这些属性,它们在那里工作得很好......
答案 0 :(得分:2)
我通过删除:
解决了这个问题<opaqueInsets>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</opaqueInsets>
我的实际JavaFX版本与SceneBuilder的版本之间似乎存在一些兼容性问题