Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Build a JavaFX Application Design a Better App Resources

Marzoog AlGhazwi
Marzoog AlGhazwi
15,796 Points

WARNING: Resource "/css/sample.css" not found.

Can someone help me to fix this !?

<GridPane fx:controller="sample.Controller"
          stylesheets="/css/sample.css"
          xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10"
          style="-fx-font-family: Papyrus">

Mistake in workspaces

5 Answers

Jan Bičan
Jan Bičan
19,777 Points

Hi, I had the same problem. Solution is to write it like this: stylesheets="@../css/sample.css"

Thank you for sharing this!

This did not work my guy more confusion :poop:

Fixed it!!!

Alright so there is a nice link to an awesome tutorial that shows the class implementation of the getResource() function being used to help solve any one's issues.

This is what I did inside of the Main.java to dissolve any additional headaches :rocket:

Check out the tutorial on that link for a cool demo project as well.

package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("/fxml/sample.fxml"));
        GridPane example = (GridPane) root;

//        Group root = new Group();
//        Text txt = new Text("Sup?");
//        txt.setFont(new Font("Papyrus", 80));
//        Label label = new Label("Name:");
//        TextField nameFld = new TextField();
////Creates the Gridpane layout
//        GridPane grid = new GridPane();
//
////        Add Items to the grid and specify the layout
////        gridlineshelp for visual debugging
////        grid.setGridLinesVisible(true);
//        grid.add(label, 0, 0);
//        grid.add(nameFld, 1, 0);
////        Adds the btn to the second column and the second row
//        Button btn = new Button();
//        btn.setText("Say Sup!");
//
//        grid.add(btn, 1, 1);
//
//        //Sets the Height gap distance
//        grid.setHgap(20);
//
//
//        txt.setY(50);
//
//        VBox box = new VBox();
//        box.getChildren().addAll(txt, grid);
//        root.getChildren().add(box);
////    Sets an event listener to listen to the action that was taken with a lambda function
//        btn.setOnAction(evt -> System.out.printf("Sup %s!%n", nameFld.getText()));

        primaryStage.setTitle("Sup");
        primaryStage.setScene(new Scene(root, 300, 275));

// THIS IS THE CODE I ADDED TO FIX THE PROBLEM 
        root.getStylesheets().add(getClass().getResource("/css/sample.css").toExternalForm());
// THIS IS THE CODE I ADDED TO FIX THE PROBLEM ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 

        primaryStage.show();
    }


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

maybe your css source file is either not included or their is a problem with workspaces .

Maybe technical problem with workspaces.

Thanks it is a good thing to help and remind each other as students and users alike that all platforms have the occasional hickups! and resolve them.