11 Replies Latest reply on May 8, 2012 12:58 AM by shakir.gusaroff

    Css issue, How can i fix this ?

    Andre Lopes
      Hi guys! Im trying to load this CSS file but this message shows up: What should i do ?

      WARNING: com.sun.javafx.css.StyleManager loadStylesheet Resource "null" not found.

      In my Code i have this in my main class :
      Scene Scene = new Scene(root,500,500);
      And this at Musica.css file :
          Document   : Musica
          Created on : 06/05/2012, 09:30:00
          Author     : André
              Purpose of the stylesheet follows.
          -fx-font-size: 16pt;
          -fx-font-family: "Courier New";
          -fx-base: rgb(132, 145, 47);
          -fx-background: rgb(225, 228, 203);
        • 1. Re: Css issue, How can i fix this ?
          David Grieve-Oracle
          What version of JavaFX are you running? Older, I think.

          Anyway, the url path should be relative to the package that your Application is in. You probably need to remove "src" from the URL path.
          • 2. Re: Css issue, How can i fix this ?
            Andre Lopes
            javafx.runtime.version: 2.0.3-b03

            That error is because he isnt finding the file ?


            same message... weird... it is in the same folder of the java source codes.. it is in in src folder

            Edited by: 932269 on 07/05/2012 16:08
            • 3. Re: Css issue, How can i fix this ?
              It's unlikely you want the src in the path because src usually refers to the source path of a build tree, not the compiled binary classpath which is where the css is really extracted from by your running app. You could still have it this way and it could still work if the src/Musica.css file got copied across to the right place in your binary build by your build system - it would just be strange.
              • 4. Re: Css issue, How can i fix this ?
                Andre Lopes
                Thanks for the answer! Could you please tell me , what path should i use ?
                I changed, but he still isnt finding, and its in the same folder of the source codes... what am i doing wrong ?

                Edited by: 932269 on 07/05/2012 16:46
                • 5. Re: Css issue, How can i fix this ?
                  1.For simplicity structure like this:
                   // scene.getStylesheets().add("stylesheet.css");
                  3. Clean and build your project:
                  • 6. Re: Css issue, How can i fix this ?
                    Andre Lopes
                    weird.! I follow the path and its all correct

                    WARNING: com.sun.javafx.css.StyleManager loadStylesheet Resource "file:/E:/ACPN%202/Netbeans%20Projetos/Musica/build/classes/musica/Musica.css" not found.

                    I tried changing from Musica to musica in file name and in the code , but still the same error.....

                    What you mean with :
                    Im using netbeans 7.1 and the package is at my pendrive in folder Netbeans Projetos/ "name of project"
                    • 7. Re: Css issue, How can i fix this ?
                      What you mean with :
                      It means your java class and css file should be in the same location:
                      • 8. Re: Css issue, How can i fix this ?
                        Andre Lopes
                        Ohh. It is already.Still doesnt work

                        Edited by: 932269 on 07/05/2012 17:28
                        • 9. Re: Css issue, How can i fix this ?
                          Andre Lopes
                          The Css File is here : E:\ACPN 2\Netbeans Projetos\Musica\src\musica
                          its in musica folder.
                          its name was musica , i changed to musica.css

                          Exception in Application start method
                          Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
                               at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
                               at com.sun.javafx.application.LauncherImpl.access$000(Unknown Source)
                               at com.sun.javafx.application.LauncherImpl$1.run(Unknown Source)
                               at java.lang.Thread.run(Thread.java:722)
                          Caused by: java.lang.NullPointerException
                               at musica.Musica.start(Musica.java:179)
                               at com.sun.javafx.application.LauncherImpl$5.run(Unknown Source)
                               at com.sun.javafx.application.PlatformImpl$4.run(Unknown Source)
                               at com.sun.javafx.application.PlatformImpl$3.run(Unknown Source)
                               at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
                               at com.sun.glass.ui.win.WinApplication.access$100(Unknown Source)
                               at com.sun.glass.ui.win.WinApplication$2$1.run(Unknown Source)
                               ... 1 more
                          Java Result: 1

                          This is the code of the program:
                          package musica;
                          import java.io.File;
                          import javafx.application.Application;
                          import javafx.beans.property.ObjectProperty;
                          import javafx.event.ActionEvent;
                          import javafx.event.EventHandler;
                          import javafx.scene.Scene;
                          import javafx.scene.control.Button;
                          import javafx.scene.control.TextField;
                          import javafx.scene.layout.GridPane;
                          import javafx.scene.layout.StackPane;
                          import javafx.scene.media.Media;
                          import javafx.scene.media.MediaErrorEvent;
                          import javafx.scene.media.MediaPlayer;
                          import javafx.scene.media.MediaView;
                          import javafx.scene.text.Font;
                          import javafx.scene.text.FontPosture;
                          import javafx.util.Duration;
                          import javax.swing.Action;
                          import javax.swing.JFileChooser;
                          import javax.swing.JOptionPane;
                          import javafx.scene.web.WebEngine;
                          import javafx.scene.web.WebView;
                          import javafx.stage.Stage;
                          import javax.swing.JTextField;
                           * @author André Lopes
                          public class Musica extends Application {
                              public MediaPlayer MP;
                              public Media Media;
                              public static String MusicURL;
                              public static JFileChooser JFC;
                              public static Duration currentTime;
                              public MediaView mediaView;
                              public static WebView view;
                              public static WebEngine webEng;
                              public static TextField webFieldURL; 
                              private static String webUrl;
                              private void init(Stage primaryStage) {
                                 view = new WebView();
                                 webEng = view.getEngine();
                                 System.out.println("Web Engine Started!");
                              public Musica()
                              webUrl = "www.google.com.br";
                              webFieldURL = new TextField(webUrl);
                              currentTime = Duration.ZERO;
                              mediaView= new MediaView(MP);
                              MusicURL = "";
                               //URL = "http://download.oracle.com/otndocs/products/javafx/oow2010-2.flv";
                              public void start(Stage primaryStage) {
                                  primaryStage.setTitle("Hello! This is Yours Music Player!");
                                  //Carrega A Web-Objects!
                                  //Botão Play
                                  Button Play = new Button();
                                  Play.setOnAction(new EventHandler<ActionEvent>() {
                                      public void handle(ActionEvent event1) {
                                          Media = new Media(MusicURL);
                                          MP = new MediaPlayer(Media);
                                          System.out.println("MediaPlayerStatus: "+ MP.getStatus());
                                          mediaView.setOnError(new EventHandler<MediaErrorEvent>() {
                                              public void handle(MediaErrorEvent arg0) {
                                                  System.out.println("MediaErrorEvent-arg0: " + MP.getStatus());
                                 //Botão para Entrar No site Digitado
                                  Button SendWebUrl = new Button();
                                  SendWebUrl.setOnAction(new EventHandler<ActionEvent>() {
                                      public void handle(ActionEvent arg0) {
                                          webUrl = webFieldURL.getText();
                                 //Botão pra escolher Musica
                                  Button SelctFileButton = new Button();
                                  SelctFileButton.setText("Music Chooser/Finder:");
                                  SelctFileButton.setOnAction(new EventHandler<ActionEvent>() {
                                        public void handle(ActionEvent arg0) {
                                          System.out.println("Java File Chooser Opened");
                                          JFileChooser search = new JFileChooser();
                                          MusicURL = search.getSelectedFile().toURI().toString();
                                          System.out.println("File URL: "+MusicURL);
                                 //Botão para pausar;
                                 Button Pause = new Button();
                                 Pause.setFont(Font.font(null, FontPosture.ITALIC,15));
                                 Pause.setOnAction(new EventHandler<ActionEvent>() {
                                      public void handle(ActionEvent arg0) {
                                      try {
                                          currentTime = MP.getCurrentTime();
                                          }catch(java.lang.NullPointerException e)
                                           System.out.println("java.lang.NullPointerException \n");   
                                           System.out.println("Error: Unable To pause! May happens if you didnt have a music Playing!");   
                                 //Botão Para Continuar;
                                 Button Continue = new Button();
                                 Continue.setOnAction(new EventHandler<ActionEvent>() {
                                      public void handle(ActionEvent arg0) {
                                  //Grid ! Layout
                                  GridPane grid = new GridPane();
                                  StackPane root = new StackPane();
                                  Scene Scene = new Scene(root,500,500);
                                  //Adicionando Botoes no Grid (Grid.add(NODE,Column,Row);
                                  webFieldURL.appendText(" ");
                              //Método para trocar de Site
                              public static void EnterWebSite(String WebUrl)
                                  System.out.println("Entering A Website!");
                                  webEng = view.getEngine();
                                  webEng.load("http://" + WebUrl);
                              public static void main(String[] args) {
                          • 10. Re: Css issue, How can i fix this ?
                            David Grieve-Oracle
                            Are you sure "file:/E:/ACPN%202/Netbeans%20Projetos/Musica/build/classes/musica/Musica.css" exists?
                            Your css file is in the same directory as your Musica application, so the following will work.
                            Or, you can use the following
                            The NullPointerException you get is because the call to getResource in the following code returns null (since there is no musica.css, it should be Musica.css)
                            Its kind of strange to see a variable with the first letter capitalized. At first I thought you were trying to call some static method on Scene - a static method which does not exist.
                            • 11. Re: Css issue, How can i fix this ?
                              Your code works for me.
                              Do you have this?
                              E:\ACPN 2\Netbeans Projetos\Musica\src\musica\Musica.java
                              E:\ACPN 2\Netbeans Projetos\Musica\src\musica\musica.css
                              If so, clean and build your project and run again
                              1 person found this helpful