Loading css using JavaFX null pointer exception in eclipse

后端 未结 4 1119
感情败类
感情败类 2021-01-20 15:24

I\'m trying to load a CSS file into JavaFX using this line of code and it gives me a null pointer exception:

scene.getStylesheets().add(welcome.class.getReso         


        
4条回答
  •  北海茫月
    2021-01-20 15:51

    Did you initialize the Scene object yet?

    //Create a scene object. Pass in the layout and set with and height
    this.scene = new Scene(layout, 600, 400);
    
    //Add CSS Style Sheet (located in same package as this class).
    String css = this.getClass().getResource("background.css").toExternalForm();
    scene.getStylesheets().add(css);
    

提交回复
热议问题