Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

FXMLLoader load from inputstream can not work with Image

907379Dec 25 2011 — edited Jan 3 2012
Hi,

I have met this problem when I practice the FXML example. According to the official example, the fxml file was load by the FXMLLoader.load the static method everything works well and the Image in the FXML file was correctly loaded.

But when I switch to use FXMLLoader object to load the fxml file from inputstream, exception was reported:

Caused by: javafx.fxml.LoadException: java.lang.InstantiationException: javafx.scene.image.Image
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.constructValue(Unknown Source)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(Unknown Source)
at javafx.fxml.FXMLLoader.processStartElement(Unknown Source)
at javafx.fxml.FXMLLoader.load(Unknown Source)
at fxmlexample.FXMLExample.start(FXMLExample.java:62)
at com.sun.javafx.application.LauncherImpl$5.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl$4.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl$3.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(Unknown Source)
at com.sun.glass.ui.win.WinApplication$2$1.run(Unknown Source)
... 1 more
Caused by: java.lang.InstantiationException: javafx.scene.image.Image
at java.lang.Class.newInstance0(Class.java:357)
at java.lang.Class.newInstance(Class.java:325)
... 12 more

The example fxml to load the image is:
<ImageView>
<image>
<Image url="@fx_boxback.jpg"/>
</image>
</ImageView>

The code generate this Exception is :
InputStream fxmlStream = null;
try{
fxmlStream = getClass().getResourceAsStream("fxml_example.fxml");
FXMLLoader loader = new FXMLLoader();

loader.setResources(ResourceBundle.getBundle("fxmlexample.fxml_example"));

//loader.setLocation(getClass().getResource(url));
Parent root =(Parent) loader.load(fxmlStream);

Scene scene = new Scene(root, 226, 264);
stage.setScene(scene);
}finally{
if(fxmlStream != null){
fxmlStream.close();
}
}
stage.show();
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 31 2012
Added on Dec 25 2011
4 comments
2,649 views