5 Replies Latest reply: May 10, 2012 10:59 PM by Andre Lopes RSS

    My Image isnt showing up , why ?

    Andre Lopes
      I tried changing things, but i have no idea what to do now.. javadoc is all in HTML/javascript Code, i dont get why...

      Heres The Code, please help me :
      /*
       * To change this template, choose Tools | Templates
       * and open the template in the editor.
       */
      package mostraimagem;
      
      import java.util.logging.Level;
      import java.util.logging.Logger;
      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.layout.StackPane;
      import javafx.stage.Stage;
      import javafx.scene.image.Image;
      import javafx.scene.*;
      import javafx.scene.image.ImageView;
      import javafx.scene.layout.GridPane;
      /**
       *
       * @author André
       */
      public class MostraImagem extends Application {
      
          public static String URL;
          //public static ImageView iv;
          public static Image image;
         
      
          public static void main(String[] args) {
              launch(args);
          }
          
          @Override
          public void start(Stage primaryStage) {
              primaryStage.setTitle("Hello World!");
           
              StackPane root = new StackPane();
              primaryStage.setScene(new Scene(root, 300, 250));
              primaryStage.show();
              
              GridPane grid = new GridPane();
              grid.setHgap(2);
              grid.setHgap(2);
              grid.setVgap(2);
              root.getChildren().add(grid);
      
              
              URL = "Lighthouse.jpg";
              Image im = new Image(URL);
              ImageView iv = new ImageView(im);
              
              iv.setVisible(true);
             
              grid.add(iv,1,5);
              
              
              
          }
          
         
      }
        • 1. Re: My Image isnt showing up , why ?
          935688
          Hi.

          I thik that Image can't find "Lighthouse.jpg" ....
          URL = "Lighthouse.jpg";
          Image im = new Image(URL);
          ImageView iv = new ImageView(im);
          public class MostraImagem extends Application {
          private static final Image im =
          new Image(MostraImagem .class.getClassLoader().getResourceAsStream("Lighthouse.jpg"));
          ...
          ....

          @Override
          public void start(Stage primaryStage) {
          .............
          ..............
          ImageView iv = new ImageView(MostraImagem.im);
          • 2. Re: My Image isnt showing up , why ?
            Andre Lopes
            Still Doesnt work! Thanks for the anwer!!! But i still need help!!
            Here are the pictures of the netbeans project and folders :

            http://imageshack.us/photo/my-images/96/netbeansproject.jpg/
            http://imageshack.us/photo/my-images/17/netbeansproject.jpg/
            /*
             * To change this template, choose Tools | Templates
             * and open the template in the editor.
             */
            package mostraimagem;
            
            import java.util.logging.Level;
            import java.util.logging.Logger;
            import javafx.application.Application;
            import javafx.event.ActionEvent;
            import javafx.event.EventHandler;
            import javafx.scene.Scene;
            import javafx.scene.control.Button;
            import javafx.scene.layout.StackPane;
            import javafx.stage.Stage;
            import javafx.scene.image.Image;
            import javafx.scene.*;
            import javafx.scene.image.ImageView;
            import javafx.scene.layout.GridPane;
            /**
             *
             * @author André
             */
            public class MostraImagem extends Application {
            
                public static String URL;
                //public static ImageView iv;
                public static Image image;
               
            
                public static void main(String[] args) {
                    launch(args);
                }
                
                @Override
                public void start(Stage primaryStage) {
                    primaryStage.setTitle("Hello World!");
                 
                    StackPane root = new StackPane();
                    primaryStage.setScene(new Scene(root, 300, 250));
                    primaryStage.show();
                    
                    GridPane grid = new GridPane();
                    grid.setHgap(2);
                    grid.setHgap(2);
                    grid.setVgap(2);
                    root.getChildren().add(grid);
            
                    
                    URL = "Lighthouse.jpg";
                    Image im = new Image(MostraImagem .class.getClassLoader().getResourceAsStream("Lighthouse.jpg"));
                    ImageView iv = new ImageView(im);
                    
                   
                    iv.setVisible(true);
                    grid.add(iv,1,5);
                    
                    
                    
                }
                
               
            }
            • 3. Re: My Image isnt showing up , why ?
              Shlomo belleli
              Hi

              I took your example
              save it inside eclipse
              change to one of my images (png file)
              the only error i fixed was a space here (look for X) "MostraImagemX.class." between the class name and the dot before the class word .
              and then run it and it's OK
              • 4. Re: My Image isnt showing up , why ?
                twasyl
                Hi there,

                Personally I don't use the ClassLoader on here. But as Shlomo belleli tested it, I guess it's not the problem. Maybe you should try specify the absolute path of the image like this:
                Image im = new Image(MostraImagem.class.getClassLoader().getResourceAsStream("/com/your/package/here/Lighthouse.jpg"));
                I always use absolute path.

                Regards.
                • 5. Re: My Image isnt showing up , why ?
                  Andre Lopes
                  Sorry For taking so long to reply.
                  Thanks For helping me! The absolute path didnt work, but, i made a test :

                  I madea copy of the picture in all folders of the project.And then it worked.
                  So i went erasing one by one to see which one was the one being used... i found out that this one is the one :

                  E:\ACPN 2\Netbeans Projetos\MostraImagem\build\classes\mostraimagem

                  Exactly here:\MostraImagem\build\classes\mostraimagem

                  Anyway. Thanks Guys!