Javafx 风格 class 路径空指针
Javafx style class path nullpointer
我正在尝试从相对路径加载 style.css,但我遇到了 nullpoiter 异常。我搜索了很多 post 仍然无法找到合适的解决方案。这是我的尝试之一:
lineChart.getStylesheets().addAll(getClass().getResource("../resources/styles/styles.css").toExternalForm());
这是我的项目结构:
试试这个:
lineChart.getStylesheets().addAll(getClass().getResource("/styles/styles.css").toExternalForm());
getResource()
查找资源文件夹,因此无需在文件路径中添加 ../resources
。
我正在尝试从相对路径加载 style.css,但我遇到了 nullpoiter 异常。我搜索了很多 post 仍然无法找到合适的解决方案。这是我的尝试之一:
lineChart.getStylesheets().addAll(getClass().getResource("../resources/styles/styles.css").toExternalForm());
这是我的项目结构:
试试这个:
lineChart.getStylesheets().addAll(getClass().getResource("/styles/styles.css").toExternalForm());
getResource()
查找资源文件夹,因此无需在文件路径中添加 ../resources
。