问题
Good Day, I a working my way through the official JavaFX FXML tutorial (See source code here). However when I compile it using the Netbeans IDE I get the following error:
Can anyone help me with this
I'm running JDK 1.7 and JavaFX 2.0
init: Deleting:
C:\Users\riash\Documents\Riaz\Personal\Java\Samples\FXMLExample\build\built-jar.properties
deps-jar: Updating property file:
C:\Users\riash\Documents\Riaz\Personal\Java\Samples\FXMLExample\build\built-jar.properties
compile: Detected JavaFX Ant API version 1.1 Launching task
from C:\Program Files (x86)\Oracle\JavaFX 2.0 SDK\tools\ant-javafx.jar
Signing JAR:
C:\Users\riash\Documents\Riaz\Personal\Java\Samples\FXMLExample\dist\FXMLExample.jar to
C:\Users\riash\Documents\Riaz\Personal\Java\Samples\FXMLExample\dist\FXMLExample.jar as nb-jfxWarning: The signer certificate will expire within six months. Enter Passphrase for keystore: Enter key password for nb-jfx: Launching task from C:\Program Files (x86)\Oracle\JavaFX 2.0 SDK\tools\ant-javafx.jar Skip jar copy to itself: FXMLExample.jar jfx-deployment: jar: run: Jun 19, 2012 9:10:33 PM javafx.fxml.FXMLLoader logException SEVERE: The following error occurred at line 48 in file
/C:/Users/riash/Documents/Riaz/Personal/Java/Samples/FXMLExample/build/classes/fxmlexample/fxml_example.fxml[Ljava.lang.StackTraceElement;@1bb3a11
Exception in Application start method
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:601)
at com.javafx.main.Main.launchApp(Main.java:453)
at com.javafx.main.Main.main(Main.java:537)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.access$000(Unknown Source)
at com.sun.javafx.application.LauncherImpl$1.run(Unknown Source)
at java.lang.Thread.run(Thread.java:722)
Caused by: javafx.fxml.LoadException: javafx.scene.layout.GridPane does not have a default property.
回答1:
Upgrading your JavaFX runtime to at least 2.1 will fix your problem.
The sample source you reference is designed for a 2.1 runtime, not a 2.0 runtime.
The reason the new source is incompatible with 2.0 is that 2.1 adds an inherited @DefaultProperty annotation to the Pane class (this annotated behaviour gets inherited by GridPane). Because of this, when you write fxml using 2.1 you can omit certain tags which get defaulted, making the 2.1 fxml less verbose than what is required for 2.0. A full explanation of this is provided by Dustin Marx in his blog.
回答2:
Upgrade from JavaFx 2.0 to JavaFx 2.2 will fix this problem.
来源:https://stackoverflow.com/questions/11111645/error-when-doing-the-javafx-fxml-tutorial-from-oracle