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!

JavaFX FXMLLoader Problem

1011660May 29 2013 — edited May 30 2013
I develop an OpenOffice addon which uses JavaFX for UI.
Code as in "JavaFX in Swing" example works fine (UI elements are created using java code).

But once I try to load UI from FXML file I face following problem:

Line on which problem happens:
parent = FXMLLoader.load(getClass().getResource("LoginDialog.fxml"));

Stack trace:

java.lang.ExceptionInInitializerError
at javafx.fxml.JavaFXBuilderFactory.<init>(JavaFXBuilderFactory.java:53)
at javafxswingapplication1.JavaFXSwingApplication1.createScene(JavaFXSwingApplication1.java:82)
at javafxswingapplication1.JavaFXSwingApplication1.access$000(JavaFXSwingApplication1.java:30)
at javafxswingapplication1.JavaFXSwingApplication1$2.run(JavaFXSwingApplication1.java:74)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:1689)
... 12 more
Exception in runnable
java.lang.NullPointerException

The code is as in netbeans example:

/**
*
* @author Alexander
*/
public class JavaFXSwingApplication1 extends JApplet {

private static final int JFXPANEL_WIDTH_INT = 300;
private static final int JFXPANEL_HEIGHT_INT = 250;
private static JFXPanel fxContainer;

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Exception e) {
}

JFrame frame = new JFrame("JavaFX 2 in Swing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JApplet applet = new JavaFXSwingApplication1();
applet.init();

frame.setContentPane(applet.getContentPane());

frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);

applet.start();
}
});
}

@Override
public void init() {
fxContainer = new JFXPanel();
fxContainer.setPreferredSize(new Dimension(JFXPANEL_WIDTH_INT, JFXPANEL_HEIGHT_INT));
add(fxContainer, BorderLayout.CENTER);
// create JavaFX scene
Platform.runLater(new Runnable() {
@Override
public void run() {
createScene();
}
});
}

private void createScene() {
Parent parent = null;

try {
parent = FXMLLoader.load(getClass().getResource("LoginDialog.fxml"));
} catch (Throwable ex) {
ex.printStackTrace();
}

Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
fxContainer.setScene(new Scene(parent));
}
}

I wonder if someone faced problem like this. Please help. I'm out of options.
I suspect the issue is somehow related with Java classloader.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 27 2013
Added on May 29 2013
5 comments
1,398 views