java.lang.IllegalArgumentException: URL non Valide ou d'une ressource non trouvée
J'ai testé ce code:
public static void main(String[] args)
{
Application.launch(args);
}
@Override
public void start(Stage primaryStage)
{
//Image
Image image = new Image("za.png");
ImageView imageView = new ImageView();
imageView.setImage(image);
//Text
Text t = new Text();
t.setText("Do you want to quit?");
//Buttons
Button btnYes = new Button("Yes");
Button btnNo = new Button("No");
btnYes.setStyle("-fx-background-color:\n"
+ " #090a0c,\n"
+ " linear-gradient(#38424b 0%, #1f2429 20%, #191d22 100%),\n"
+ " linear-gradient(#20262b, #191d22),\n"
+ " radial-gradient(center 50% 0%, radius 100%, rgba(114,131,148,0.9), rgba(255,255,255,0));\n"
+ " -fx-background-radius: 5,4,3,5;\n"
+ " -fx-background-insets: 0,1,2,0;\n"
+ " -fx-text-fill: white;\n"
+ " -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 5, 0.0 , 0 , 1 );\n"
+ " -fx-font-family: \"Arial\";\n"
+ " -fx-text-fill: linear-gradient(white, #d0d0d0);\n"
+ " -fx-font-size: 12px;\n"
+ " -fx-padding: 10 20 10 20;");
btnNo.setStyle("-fx-background-color:\n"
+ " #090a0c,\n"
+ " linear-gradient(#38424b 0%, #1f2429 20%, #191d22 100%),\n"
+ " linear-gradient(#20262b, #191d22),\n"
+ " radial-gradient(center 50% 0%, radius 100%, rgba(114,131,148,0.9), rgba(255,255,255,0));\n"
+ " -fx-background-radius: 5,4,3,5;\n"
+ " -fx-background-insets: 0,1,2,0;\n"
+ " -fx-text-fill: white;\n"
+ " -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.6) , 5, 0.0 , 0 , 1 );\n"
+ " -fx-font-family: \"Arial\";\n"
+ " -fx-text-fill: linear-gradient(white, #d0d0d0);\n"
+ " -fx-font-size: 12px;\n"
+ " -fx-padding: 10 20 10 20;");
//Buttons layout
HBox hbox = new HBox(8); //spacing = 8
hbox.setStyle("-fx-padding: 15; -fx-font-size: 15pt;");
hbox.getChildren().addAll(btnYes, btnNo);
hbox.setAlignment(Pos.BASELINE_RIGHT);
BorderPane bp = new BorderPane();
bp.setStyle("-fx-background-color: linear-gradient(#ffffff,#f3f3f4);\n"
+ " -fx-border-width: 1 1 1 1;\n"
+ " -fx-border-color: #b4b4b4 transparent #b4b4b4 transparent;\n"
+ " -fx-font-size: 1.083333em;\n"
+ " -fx-text-fill: #292929;");
bp.setPadding(new Insets(10, 20, 10, 20));
//Button btnTop = new Button("Top");
bp.setTop(null);
//Button btnLeft = new Button("Left");
bp.setLeft(imageView);
//Button btnCenter = new Button("Center");
bp.setCenter(t);
//Button btnRight = new Button("Right");
bp.setRight(null);
//Button btnBottom = new Button("Bottom");
bp.setBottom(hbox);
Scene scene = new Scene(bp, 500, 200);
primaryStage.setScene(scene);
primaryStage.show();
}
J'obtiens cette erreur:
Executing com.javafx.main.Main from /home/rcbandit/Desktop/test/DX-57DC/dist/run429319394/DX-57DC.jar using platform /opt/jdk1.8.0/bin/java
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.javafx.main.Main.launchApp(Main.java:642)
at com.javafx.main.Main.main(Main.java:805)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Thread.java:724)
Caused by: java.lang.IllegalArgumentException: Invalid URL: Invalid URL or resource not found
at javafx.scene.image.Image.validateUrl(Image.java:986)
at javafx.scene.image.Image.<init>(Image.java:538)
at com.dx57dc.main.DX57DC.start(DX57DC.java:28)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:215)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication$3$1.run(GtkApplication.java:82)
... 1 more
Caused by: java.lang.IllegalArgumentException: Invalid URL or resource not found
at javafx.scene.image.Image.validateUrl(Image.java:979)
... 12 more
Java Result: 1
Deleting directory /home/rcbandit/Desktop/test/DX-57DC/dist/run429319394
jfxsa-run:
BUILD SUCCESSFUL (total time: 6 seconds)
J'ai placé le fichier image à côté du code source java fichier, mais le fichier n'est pas trouvé. Pouvez-vous me dire comment résoudre ce problème?
OriginalL'auteur Peter Penzov | 2013-06-07
Vous devez vous connecter pour publier un commentaire.
Ne
Ou tout simplement
OriginalL'auteur Uluk Biy
Le constructeur de cette doit pointer vers un URI, de sorte qu'il serait:
Alternativement, vous pouvez faire:
La plupart des méthodes et des constructeurs en JavaFX, qui prend une chaîne de caractères comme paramètre de cette façon (c'est à dire la spécification d'une ressource) faire via la chaîne URI plutôt que juste un simple chemin d'accès au fichier ou d'une URL.
no suitable constructor found for Image(URI)
Désolé, doit avoir été un toString (). Édité maintenant.
Cette solution a fonctionné pour moi alors que l'on a accepté la réponse n'a pas.
OriginalL'auteur Michael Berry