-
Bug
-
Resolution: Fixed
-
P4
-
None
-
None
When calling StyleManager.addUserAgentStylesheet() before the first Node is created and PlatformImpl.setDefaultPlatformUserAgentStylesheet() is invoked by the initialization of the Node a Exception will be thrown.
Example:
public class ButtonDemo extends Application {
@Override
public void start(Stage stage) throws Exception {
StyleManager.getInstance().addUserAgentStylesheet(AquaFx.class.getResource("mac_os.css").toExternalForm());
new TextField();
}
}
will end in
Exception in Application start method
Exception in thread "main" 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:483)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:751)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:548)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:48)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:134)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ExceptionInInitializerError
at de.zillmann.javafx.aqua.demo.ButtonDemo.start(ButtonDemo.java:36)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:491)
at com.sun.javafx.application.PlatformImpl$6.run(PlatformImpl.java:260)
at com.sun.javafx.application.PlatformImpl$5$1.run(PlatformImpl.java:223)
at com.sun.javafx.application.PlatformImpl$5$1.run(PlatformImpl.java:220)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:220)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
Caused by: java.lang.NullPointerException
at com.sun.javafx.css.StyleManager.getIndex(StyleManager.java:787)
at com.sun.javafx.css.StyleManager.setDefaultUserAgentStylesheet(StyleManager.java:895)
at com.sun.javafx.css.StyleManager.setDefaultUserAgentStylesheet(StyleManager.java:879)
at com.sun.javafx.application.PlatformImpl$10.run(PlatformImpl.java:496)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.setPlatformUserAgentStylesheet(PlatformImpl.java:493)
at com.sun.javafx.application.PlatformImpl.setDefaultPlatformUserAgentStylesheet(PlatformImpl.java:474)
at javafx.scene.control.Control.<clinit>(Control.java:81)
... 8 more
Changing the order in code will work because "new TextField()" calls PlatformImpl.setDefaultPlatformUserAgentStylesheet()
public class ButtonDemo extends Application {
@Override
public void start(Stage stage) throws Exception {
new TextField();
StyleManager.getInstance().addUserAgentStylesheet(AquaFx.class.getResource("mac_os.css").toExternalForm());
}
}
Here is another example: http://www.guigarage.com/2013/03/global-stylesheet-for-your-javafx-application/
Example:
public class ButtonDemo extends Application {
@Override
public void start(Stage stage) throws Exception {
StyleManager.getInstance().addUserAgentStylesheet(AquaFx.class.getResource("mac_os.css").toExternalForm());
new TextField();
}
}
will end in
Exception in Application start method
Exception in thread "main" 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:483)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:751)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:548)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:48)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:134)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.ExceptionInInitializerError
at de.zillmann.javafx.aqua.demo.ButtonDemo.start(ButtonDemo.java:36)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:491)
at com.sun.javafx.application.PlatformImpl$6.run(PlatformImpl.java:260)
at com.sun.javafx.application.PlatformImpl$5$1.run(PlatformImpl.java:223)
at com.sun.javafx.application.PlatformImpl$5$1.run(PlatformImpl.java:220)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:220)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
Caused by: java.lang.NullPointerException
at com.sun.javafx.css.StyleManager.getIndex(StyleManager.java:787)
at com.sun.javafx.css.StyleManager.setDefaultUserAgentStylesheet(StyleManager.java:895)
at com.sun.javafx.css.StyleManager.setDefaultUserAgentStylesheet(StyleManager.java:879)
at com.sun.javafx.application.PlatformImpl$10.run(PlatformImpl.java:496)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.setPlatformUserAgentStylesheet(PlatformImpl.java:493)
at com.sun.javafx.application.PlatformImpl.setDefaultPlatformUserAgentStylesheet(PlatformImpl.java:474)
at javafx.scene.control.Control.<clinit>(Control.java:81)
... 8 more
Changing the order in code will work because "new TextField()" calls PlatformImpl.setDefaultPlatformUserAgentStylesheet()
public class ButtonDemo extends Application {
@Override
public void start(Stage stage) throws Exception {
new TextField();
StyleManager.getInstance().addUserAgentStylesheet(AquaFx.class.getResource("mac_os.css").toExternalForm());
}
}
Here is another example: http://www.guigarage.com/2013/03/global-stylesheet-for-your-javafx-application/