Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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.