1 Reply Latest reply: Aug 11, 2013 6:21 AM by JohnMefster RSS

    CSS Error in running javafx application after move to use jdk8

    JohnMefster

      Hi all,

       

      I'm running an javafx app fine with build: jdk-8-ea-b36e-linux-arm-hflt-29_nov_2012 which uses jdk7 perfectly fine on the raspberry pi (which i also keep as backup until newer builds well, are starting to work with my app).

       

      I'm getting an exception related to CSS (seems to me) when i try to run my javafx app (as well through netbeans on windows xp as through command line on the raspberry pi):

      I've try'd two netbeans versions, the stable 7.3 with jdk 1.8 build 100 and nightly 7.4 with the same jdk 1.8 build. Building goes fine on both these versions.

       

      The exception is:

      Exception in thread "JavaFX Application Thread"
         java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
         at java.util.ArrayList.rangeCheck(ArrayList.java:638)
         at java.util.ArrayList.get(ArrayList.java:414)
         at com.sun.javafx.css.StyleMap.getCascadingStyles(StyleMap.java:121)
         at javafx.scene.CssStyleHelper.getStyle(CssStyleHelper.java:683)
         at javafx.scene.CssStyleHelper.lookupFont(CssStyleHelper.java:1548)
         at javafx.scene.CssStyleHelper.transitionToState(CssStyleHelper.java:460)
         at javafx.scene.Node.impl_processCSS(Node.java:8665)
         at javafx.scene.Parent.impl_processCSS(Parent.java:1192)
         at javafx.scene.Parent.impl_processCSS(Parent.java:1204)
         at javafx.scene.Node.processCSS(Node.java:8575)
         at javafx.scene.Scene.doCSSPass(Scene.java:538)
         at javafx.scene.Scene.preferredSize(Scene.java:1503)
         at javafx.scene.Scene.impl_preferredSize(Scene.java:1570)
         at javafx.stage.Window$9.invalidated(Window.java:733)
         at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:109)
         at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:143)
         at javafx.stage.Window.setShowing(Window.java:799)
         at javafx.stage.Window.show(Window.java:814)
         at javafx.stage.Stage.show(Stage.java:243)
         at pidome.client.PidomeClient$1$1.run(Unknown Source)
         at com.sun.javafx.application.PlatformImpl$5$1.run(PlatformImpl.java:244)
         at com.sun.javafx.application.PlatformImpl$5$1.run(PlatformImpl.java:241)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:241)
         at com.sun.glass.ui.lens.LensApplication$RunnableEvent.dispatch(LensApplication.java:169)
         at com.sun.glass.ui.lens.LensApplication._runLoop(LensApplication.java:756)
         at com.sun.glass.ui.lens.LensApplication.access$700(LensApplication.java:55)
         at com.sun.glass.ui.lens.LensApplication$4.run(LensApplication.java:815)
         at java.lang.Thread.run(Thread.java:724)
      java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
         at java.util.ArrayList.rangeCheck(ArrayList.java:638)
         at java.util.ArrayList.get(ArrayList.java:414)
         at com.sun.javafx.css.StyleMap.getCascadingStyles(StyleMap.java:121)
         at javafx.scene.CssStyleHelper.getStyle(CssStyleHelper.java:683)
         at javafx.scene.CssStyleHelper.lookupFont(CssStyleHelper.java:1548)
         at javafx.scene.CssStyleHelper.transitionToState(CssStyleHelper.java:460)
         at javafx.scene.Node.impl_processCSS(Node.java:8665)
         at javafx.scene.Parent.impl_processCSS(Parent.java:1192)
         at javafx.scene.Parent.impl_processCSS(Parent.java:1204)
         at javafx.scene.Node.processCSS(Node.java:8575)
         at javafx.scene.Node.processCSS(Node.java:8566)
         at javafx.scene.Scene.doCSSPass(Scene.java:538)
         at javafx.scene.Scene.access$3600(Scene.java:189)
         at javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2294)
         at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:325)
         at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:533)
         at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:513)
         at com.sun.javafx.tk.quantum.QuantumToolkit$16.run(QuantumToolkit.java:380)
         at com.sun.glass.ui.lens.LensApplication$RunnableEvent.dispatch(LensApplication.java:169)
         at com.sun.glass.ui.lens.LensApplication._runLoop(LensApplication.java:756)
         at com.sun.glass.ui.lens.LensApplication.access$700(LensApplication.java:55)
         at com.sun.glass.ui.lens.LensApplication$4.run(LensApplication.java:815)
         at java.lang.Thread.run(Thread.java:724)
      
      

       

      On line 22 is where i think my problem really begins. This line correspondents to my code on line 14:

          @Override
          public void start(Stage primaryStage) {
              redirectOutputToLog();
              rootStage = primaryStage;
              rootStage.setTitle("PiDome Client");
              rootStage.setFullScreen(true);
              rootStage.initStyle(StageStyle.UNDECORATED);
              ready.addListener(new ChangeListener<Boolean>(){
                  @Override
                  public void changed(
                      ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
                          if (Boolean.TRUE.equals(t1)) {
                              rootStage.setScene(mainStage.scene());
                              rootStage.show();
                         }
                      }
              });
              initialize();
          }
      
      

       

      The rest of my main file is as follows (snippet):

      public class PidomeClient extends Application implements NetworkingEventListener,ClientDataConnectionListener,DomoticsEventListener,MainSceneEventListener,PreloaderCredentials {
      
      MainScene mainStage;
      BooleanProperty ready = new SimpleBooleanProperty(false);
      
        public void start(Stage primaryStage){
        /* See above snippet */
        }
      
          public final void initialize(){
              /* code */
              mainStage = new MainScene();
              /* code */
          }
      
        /* some functions for the listeners added */
      
          @Override
          public void handleMainSceneEvent(MainSceneEvent event) {
              if(event.getEventType().equals(MainSceneEvent.SCENEBUILDDONE)){
                  notifyPreloader(new StateChangeNotification(StateChangeNotification.Type.BEFORE_START));
                  ready.setValue(Boolean.TRUE);
              }
          }
      
      

       

      Some code from my MainScene class:

      public final class MainScene {
         
          Pane root = new Pane();
          Scene appScene = new Scene(root, DisplayConfig.getScreenWidth(), DisplayConfig.getScreenHeight());
          
          String theme = Theme.getCurrent();
         
          NotificationBar notBar = new NotificationBar();
          TopBar topBar          = new TopBar();
          MainControl mainControl= new MainControl();
          BottomBar bottomBar    = new BottomBar();
          //Console   console      = new Console();
         
          SubControl subControl     = new SubControl();   
          
        public MainScene(){
             
          }
         
          public final void createScene(){
              LOG.debug("Screen dimensions: width: {}, height: {}",DisplayConfig.getScreenWidth(), DisplayConfig.getScreenHeight());
              root.getStylesheets().add(theme + "main.css");
              root.getChildren().add(notBar);
              root.getChildren().add(topBar);
              root.getChildren().add(mainControl);
              root.getChildren().add(bottomBar);
              root.getChildren().add(subControl);
             
              //console.show();
              _fireSceneBuildDone();
          }
         
          public final Scene scene(){
              return appScene;
          }
         
          public final void stop(){
              //topBar.stopThreads();
          }
         
          public synchronized static void addDoneListener(MainSceneEventListener l){
              _listeners.add(l);
          }
         
          final synchronized void _fireSceneBuildDone(){
              LOG.debug("New event: {}", MainSceneEvent.SCENEBUILDDONE);
              MainSceneEvent serviceEvent = new MainSceneEvent(this, MainSceneEvent.SCENEBUILDDONE);
              Iterator listeners = _listeners.iterator();
              while (listeners.hasNext()) {
                  ((MainSceneEventListener) listeners.next()).handleMainSceneEvent(serviceEvent);
              }
          }
         
      }
      
      

       

      Further explanation:

      The lines 8 until 14 are the children that have they're own CSS files which are included, they do not contain the .root element. This element is only present in the main.css class. As you can see i'm using a preloader which also has it's own CSS but with the .root element, but this one does not contain anything related to fonts. I have try'd a lot of things because i'm thinking i'm in error because i have seen this on the javafx 8 Performance ideas page (https://wiki.openjdk.java.net/display/OpenJFX/Performance+Ideas): "Rather than running CSS at start up, precompute the defaults and initialize FX to have these values.  This should improve start up time." I do not know if this is related. What i've tryed is

      - move the children created in MainScene to another location,

      - Completely discard the preloader (as wel as in netbeans is in the code),

      - Removed everything that was font related out of my css,

      - Removed everything that was font related from my code,

      - Removed the traling slash to the path to the css returned by my function theme.getCurrent(); But then i get the error that the file is not found.

      - Went completely procedural when creating the scene objects and children.

       

      I posted a recent amount of  code, and, i'm out of options at the moment. So, is there a bug or am i doing something wrong and should i rethink on how CSS is handled in FX 8?

       

      Best regards,

      John

       

      Some changes in explanation. Message was edited by: JohnMefster

        • 1. Re: CSS Error in running javafx application after move to use jdk8
          JohnMefster

          Well, i found the/a solution for the above:

           

          I've put all my css in one file, and found some empty declarations like #mainbottomcontainer .content .label { }. I removed these 3 empty declarations and now my app also works in build 101. So i do now think this has to do with the CSS remark posted above. And i do think this is due to setting CSS in the declaration part of a class at startup (like in my MainScene class above), but i'm not sure. But, it is fixed for now.

           

          John.