Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 15 of 15

Thread: Makes no sense...

  1. #1
    Member MrLowBot's Avatar
    Join Date
    Nov 2018
    Location
    Sweden
    Posts
    130
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Makes no sense...

    package HW.JavaFXUI;
     
    import javafx.application.Application;
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.control.ContentDisplay;
    import javafx.scene.control.Label;
    import javafx.scene.image.Image;
    import javafx.scene.image.ImageView;
    import javafx.scene.layout.HBox;
    import javafx.scene.layout.StackPane;
    import javafx.scene.paint.Color;
    import javafx.scene.shape.Circle;
    import javafx.scene.shape.Rectangle;
    import javafx.scene.shape.Ellipse;;
     
    public class LabelWithGraphic extends Application {
     
    	public static void main(String[] args) {
    		launch(args);
    	}
     
    	@Override // Override the start method in the application class.
    	public void start(Stage primaryStage) throws Exception {
    		ImageView us = new ImageView(new Image("image/us.gif"));
    		Label lb1 = new Label("US\n50 States", us);
    		lb1.setStyle("-fx-border-color: green; -fx-border-widht: 2");
    		lb1.setContentDisplay(ContentDisplay.BOTTOM);
    		lb1.setTextFill(Color.RED);
     
    		Label lb2 = new Label("Circle", new Circle(50, 50, 25));
    		lb2.setContentDisplay(ContentDisplay.TOP);
    		lb2.setTextFill(Color.ORANGE);
     
    		Label lb3 = new Label("Rectangle", new Rectangle(10, 10, 50, 25));
    		lb3.setContentDisplay(ContentDisplay.RIGHT);
     
    		Label lb4 = new Label("Ellipse", new Ellipse(50, 50, 50, 25));
    		lb4.setContentDisplay(ContentDisplay.LEFT);
     
    		Ellipse ellipse = new Ellipse(50, 50, 50, 25);
    		ellipse.setStroke(Color.GREEN);
    		ellipse.setFill(Color.WHITE);
    		StackPane stackpane = new StackPane();
    		stackpane.getChildren().addAll(ellipse, new Label("JavaFX"));
    		Label lb5 = new Label("A pane inside a label", stackpane);
    		lb5.setContentDisplay(ContentDisplay.BOTTOM);
     
    		HBox pane = new HBox(20);
    		pane.getChildren().addAll(lb1, lb2, lb3, lb4, lb4);
     
    		// Create a scene and place it in the stage.
     
    		Scene scene = new Scene(pane, 450, 150);
    		primaryStage.setTitle("LabelWithGraphic"); // Set the stage title.
    		primaryStage.setScene(scene); // Place the scene in the stage.
    		primaryStage.show();
     
    	}
     
    }
    Last edited by MrLowBot; October 4th, 2019 at 08:31 PM.
    "Tick, tack"

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Makes no sense...

    I get an execution error. Check to make sure you have not missed the execution error.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member MrLowBot's Avatar
    Join Date
    Nov 2018
    Location
    Sweden
    Posts
    130
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Makes no sense...

    Honestly... i cannot seem to find the problem here.
    "Tick, tack"

  4. #4
    Member MrLowBot's Avatar
    Join Date
    Nov 2018
    Location
    Sweden
    Posts
    130
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Makes no sense...

    Quote Originally Posted by Norm View Post
    I get an execution error. Check to make sure you have not missed the execution error.
    Exception in Application start method
    java.lang.reflect.InvocationTargetException
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    	at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
    Caused by: java.lang.RuntimeException: Exception in Application start method
    	at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
    	at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$159(LauncherImpl.java:182)
    	at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.IllegalArgumentException: Invalid URL: Invalid URL or resource not found
    	at javafx.scene.image.Image.validateUrl(Image.java:1118)
    	at javafx.scene.image.Image.<init>(Image.java:620)
    	at HW.JavaFXUI.LabelWithGraphic.start(LabelWithGraphic.java:25)
    	at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$166(LauncherImpl.java:863)
    	at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$179(PlatformImpl.java:326)
    	at com.sun.javafx.application.PlatformImpl.lambda$null$177(PlatformImpl.java:295)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at com.sun.javafx.application.PlatformImpl.lambda$runLater$178(PlatformImpl.java:294)
    	at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    	at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    	at com.sun.glass.ui.win.WinApplication.lambda$null$152(WinApplication.java:177)
    	... 1 more
    Caused by: java.lang.IllegalArgumentException: Invalid URL or resource not found
    	at javafx.scene.image.Image.validateUrl(Image.java:1110)
    	... 11 more
    Exception running application HW.JavaFXUI.LabelWithGraphic

    This is the result. What i should be getting is a window with 4 different shapes displayed. And yes, i do have javaFx lib.
    And yes i tried to update everything that could be updated.
    Last edited by MrLowBot; October 5th, 2019 at 04:43 AM.
    "Tick, tack"

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Makes no sense...

    Caused by: java.lang.IllegalArgumentException: Invalid URL: Invalid URL or resource not found
    at javafx.scene.image.Image.validateUrl(Image.java:11 18)
    at javafx.scene.image.Image.<init>(Image.java:620)
    at HW.JavaFXUI.LabelWithGraphic.start(LabelWithGraphic.java:25)
    Scan through the text of the error message until you find a reference to a line in your code. This part of the message refers to line 25 and says there is a problem there with a URL. That line has a path to an image. Check that the image file is at that address.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Member MrLowBot's Avatar
    Join Date
    Nov 2018
    Location
    Sweden
    Posts
    130
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Makes no sense...

    Quote Originally Posted by Norm View Post
    Scan through the text of the error message until you find a reference to a line in your code. This part of the message refers to line 25 and says there is a problem there with a URL. That line has a path to an image. Check that the image file is at that address.
    Yeah i can see that but i cannot find the url problem. I have looked over all the lib and the code many times.
    Mind you, this is all from a book but they never mentioned anything about the url or an image.
    I do appreciate you helping me. PS: Doing this on my free time.
    "Tick, tack"

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Makes no sense...

    anything about the url or an image.
    Look at the statement on line 25.
    Where is the us.gif file? Is it in the image folder? Is the image folder in the current directory when the code is executed?
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Member MrLowBot's Avatar
    Join Date
    Nov 2018
    Location
    Sweden
    Posts
    130
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Makes no sense...

    Quote Originally Posted by Norm View Post
    Look at the statement on line 25.
    Where is the us.gif file? Is it in the image folder? Is the image folder in the current directory when the code is executed?
    I have my gif file within the package... it is laying right next to the class. I've never had a problem doing that before.
    "Tick, tack"

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Makes no sense...

    The program is coded to look in the image folder for the image file. And the image folder must be available to the java command when it executes (ie in the current directory where the java command is executed.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Member MrLowBot's Avatar
    Join Date
    Nov 2018
    Location
    Sweden
    Posts
    130
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Makes no sense...

    If i knew what image folder you were talking about then this would be done... not you're fault at all. Just i've not been able to anything as such. I even made a source folder for the image within the project.
    "Tick, tack"

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Makes no sense...

    what image folder
    Look at the statement on line 25:
    ImageView us = new ImageView(new Image("image/us.gif"));
    the code refers to a file: us.gif in a folder named: image
    If you don't understand my answer, don't ignore it, ask a question.

  12. #12
    Member MrLowBot's Avatar
    Join Date
    Nov 2018
    Location
    Sweden
    Posts
    130
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Makes no sense...

    Quote Originally Posted by Norm View Post
    Look at the statement on line 25:
    the code refers to a file: us.gif in a folder named: image
    Yes. I have the gif within the same package as the class. So it should work, since i've done it before and it had been working before as well.
    But it doesn't want to work. The "gif", which i changed to a png now, is laying next to the class.

    ImageView us = new ImageView(new Image("us.png"));

    Here is the code again :

    package HW.JavaFXUI;
     
    import javafx.application.Application;
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.control.ContentDisplay;
    import javafx.scene.control.Label;
    import javafx.scene.image.Image;
    import javafx.scene.image.ImageView;
    import javafx.scene.layout.HBox;
    import javafx.scene.layout.StackPane;
    import javafx.scene.paint.Color;
    import javafx.scene.shape.Circle;
    import javafx.scene.shape.Rectangle;
    import javafx.scene.shape.Ellipse;;
     
    public class LabelWithGraphic extends Application {
     
    	public static void main(String[] args) {
    		launch(args);
    	}
     
    	@Override // Override the start method in the application class.
    	public void start(Stage primaryStage) throws Exception {
    		ImageView us = new ImageView(new Image("us.png"));
    		Label lb1 = new Label("US\n50 States", us);
    		lb1.setStyle("-fx-border-color: green; -fx-border-widht: 2");
    		lb1.setContentDisplay(ContentDisplay.BOTTOM);
    		lb1.setTextFill(Color.RED);
     
    		Label lb2 = new Label("Circle", new Circle(50, 50, 25));
    		lb2.setContentDisplay(ContentDisplay.TOP);
    		lb2.setTextFill(Color.ORANGE);
     
    		Label lb3 = new Label("Rectangle", new Rectangle(10, 10, 50, 25));
    		lb3.setContentDisplay(ContentDisplay.RIGHT);
     
    		Label lb4 = new Label("Ellipse", new Ellipse(50, 50, 50, 25));
    		lb4.setContentDisplay(ContentDisplay.LEFT);
     
    		Ellipse ellipse = new Ellipse(50, 50, 50, 25);
    		ellipse.setStroke(Color.GREEN);
    		ellipse.setFill(Color.WHITE);
    		StackPane stackpane = new StackPane();
    		stackpane.getChildren().addAll(ellipse, new Label("JavaFX"));
    		Label lb5 = new Label("A pane inside a label", stackpane);
    		lb5.setContentDisplay(ContentDisplay.BOTTOM);
     
    		HBox pane = new HBox(20);
    		pane.getChildren().addAll(lb1, lb2, lb3, lb4, lb4, lb5, ellipse);
     
     
    		// Create a scene and place it in the stage.
     
    		Scene scene = new Scene(pane, 450, 150);
    		primaryStage.setTitle("LabelWithGraphic"); // Set the stage title.
    		primaryStage.setScene(scene); // Place the scene in the stage.
    		primaryStage.show();
     
    	}
     
    }
    "Tick, tack"

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Makes no sense...

    it doesn't want to work
    What error messages are shown?
    Please copy the full text of the error message and paste it here. It has important info about the error.
    If you don't understand my answer, don't ignore it, ask a question.

  14. #14
    Member MrLowBot's Avatar
    Join Date
    Nov 2018
    Location
    Sweden
    Posts
    130
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Makes no sense...

    Exception in Application start method
    java.lang.reflect.InvocationTargetException
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    	at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
    Caused by: java.lang.RuntimeException: Exception in Application start method
    	at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
    	at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$159(LauncherImpl.java:182)
    	at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.IllegalArgumentException: Invalid URL: Invalid URL or resource not found
    	at javafx.scene.image.Image.validateUrl(Image.java:1118)
    	at javafx.scene.image.Image.<init>(Image.java:620)
    	at HW.JavaFXUI.LabelWithGraphic.start(LabelWithGraphic.java:25)
    	at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$166(LauncherImpl.java:863)
    	at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$179(PlatformImpl.java:326)
    	at com.sun.javafx.application.PlatformImpl.lambda$null$177(PlatformImpl.java:295)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at com.sun.javafx.application.PlatformImpl.lambda$runLater$178(PlatformImpl.java:294)
    	at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    	at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    	at com.sun.glass.ui.win.WinApplication.lambda$null$152(WinApplication.java:177)
    	... 1 more
    Caused by: java.lang.IllegalArgumentException: Invalid URL or resource not found
    	at javafx.scene.image.Image.validateUrl(Image.java:1110)
    	... 11 more
    Exception running application HW.JavaFXUI.LabelWithGraphic

    Line 25 is the problem, but no problem is showing up in the code until execution.
    Line 25 is this:
    ImageView us = new ImageView(new Image("us.png"));
    "Tick, tack"

  15. #15
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Makes no sense...

    The program can not find the file. Make sure the correct file name is used and that the file is present.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. BorderLayout makes everything disappear
    By jason3460 in forum AWT / Java Swing
    Replies: 1
    Last Post: December 6th, 2013, 03:35 AM
  2. Audioclip play makes applets slow
    By Marcus in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 19th, 2010, 01:20 PM