I am having problem in adding logo to my javafx desktop application. The error received is "Invalid URL: Invalid URL or resource not found". I checked for this but there was no such mistake.
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.*;
import javafx.application.Application;
import javafx.fxml.*;
public class Main extends Application{
public static void main(String[] args) {
Application.launch(args);
}
public void start(Stage primaryStage) {
try {
primaryStage.setTitle("App");
primaryStage.setIconified(true);
primaryStage.getIcons().add(new Image("logo.jpg"));
AnchorPane root=new AnchorPane();
root = FXMLLoader.load(getClass().getResource("Sample.fxml"));
Scene s=new Scene(root, 800, 600);
primaryStage.setScene(s);
primaryStage.show();
}
catch(Exception e) {
e.printStackTrace();
}
}
}
"Sample.fxml"needs to be in the same package as the class