【问题标题】:JavaFX CSS Parsing ErrorJavaFX CSS 解析错误
【发布时间】:2016-08-15 04:29:07
【问题描述】:

我收到此错误:

com.sun.javafx.css.parser.CSSParser parse WARNING: CSS Error parsing file:/filepath/bin/: 预期 LBRACE 在 [-1,-1]

我的代码如下:

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class Main extends Application {

public static void main(String[] args) {
    launch(args);
}

public void start(Stage primaryStage) throws Exception {
    StackPane root = new StackPane();
    Scene mainScene = new Scene(root, 800, 600);
    mainScene.getStylesheets().clear();
    mainScene.getStylesheets().add("//stylesheet.css");
    primaryStage.setTitle("Not Facebook");
    primaryStage.setScene(mainScene);
    primaryStage.show();
    //loadGame(primaryStage);

}

public void loadGame(Stage primaryStage) {
    GridPane grid = new GridPane();
    grid.setHgap(0);
    grid.setVgap(0);
    grid.setPadding(new Insets(10, 10, 10, 10));
    Text text = new Text("Hello");
    grid.add(text, 5,5);
    Scene gameScene = new Scene(grid, 800, 600);
    primaryStage.setScene(gameScene);
}

}
.root {
  -fx-background-color: #333333;
}

我已经搜索过,但没有人遇到同样的问题,我不知道为什么会这样。

【问题讨论】:

    标签: java css javafx


    【解决方案1】:

    样式表的路径错误。

    使用

    mainScene.getStylesheets().add("stylesheet.css");
                                   ^^
    

    而不是

    mainScene.getStylesheets().add("//stylesheet.css");
                                    ^^
    

    请注意,您甚至不需要单个前导 / 来访问相对于应用程序根类路径的样式表。来自JavaDoc:

    URL 是表单的分层 URI [方案:][//权威][路径]。如果 URL 没有 [scheme:] 组件,URL 仅被视为 [path] 组件。 任何 [path] 的前导 '/' 字符被忽略并且 [path] 是 被视为相对于应用程序类路径的根的路径。

    【讨论】:

      猜你喜欢
      • 2014-11-08
      • 1970-01-01
      • 1970-01-01
      • 2016-09-28
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 2017-01-21
      • 2018-04-05
      相关资源
      最近更新 更多