2016-08-15 12 views
2

이 오류 받고 있어요자바 FX CSS 구문 분석 오류

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; 
} 

내가 검색 한을하지만 아무도 같은 문제가 없습니다 내가 돈 왜 이런 일이 일어나는지 알지 못합니다.

답변

1

스타일 시트 경로가 잘못되었습니다.

사용 당신도 필요하지 않습니다

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

대신

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

참고 단일 /를 선도하는 응용 프로그램의 루트 클래스 경로에 스타일 시트 상대에 액세스 할 수 있습니다. JavaDoc :

The URL is a hierarchical URI of the form [scheme:][//authority][path]. If the URL does not have a [scheme:] component, the URL is considered to be the [path] component only. Any leading '/' character of the [path] is ignored and the [path] is treated as a path relative to the root of the application's classpath.