My Code
package main;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
import javafx.scene.media.AudioClip;
import javafx.scene.text.Font;
import javafx.stage.Stage;
public class Main extends Application {
public void start(Stage primaryStage) throws Exception {
Font font = Font.loadFont( Main.class.getClassLoader().getResourceAsStream("resources/TRON.TTF"), 10);
//ImageView image = new ImageView(new Image("file:outside/bell.png"));
ImageView image = new ImageView(new Image("resources/images/redseven.png"));
//This works when file is outside src folder
//AudioClip audio = new AudioClip("file:sounds/win.wav");
//doesn't work
//AudioClip audio = new AudioClip("file:resources/sounds/win.wav");
//doesn't work
AudioClip audio = new AudioClip("resources/sounds/win.wav");
audio.play();
VBox pane = new VBox();
Label label = new Label("Text");
label.setStyle("-fx-font-family:'Tron'; -fx-font-size: 50px;-fx-text-fill: red");
pane.getChildren().addAll(label, image);
Scene scene = new Scene(pane, 500, 500);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
My Project directory
Output
Caused by: java.lang.IllegalArgumentException: uri.getScheme() == null! uri == 'resources/sounds/win.wav'
The image url's work when they are outside src folder and inside src folder. When they are outside I have to include "file:" before the url as shown in the code.
Audioclip irls work when they are file is outside src. But doesn't work when it's inside.
EDIT
Doing this works. But I'm not really sure why?
AudioClip audio = new AudioClip("file:src/resources/sounds/win.wav");
I added the src folder also to the url and then added "file:" infront of it. Why doesn't it work with relative path? The image is loaded without any problem.