I've searched the stackoverflow but no solutions are working for my code.
The image for some reason isn't rendering. There is no Icon for the Stage
I tried this: JavaFX Image not showing in stage but the image still wouldn't render. Code:
package com.example.javafxfirst;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.stage.Stage;
import javafx.scene.paint.Color;
import java.io.File;
public class HelloApplication extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
//Stage stage = new Stage();
Group root = new Group();
Scene scene = new Scene(root,Color.BLACK);
Image icon = new Image(new File("resources/javafxlogo.png").toURI().toString());
stage.getIcons().add(icon);
stage.setTitle("Program");
stage.setScene(scene);
stage.show();
}
}
Update:
I replaced
Image icon = new Image(new File("resources/javafxlogo.png").toURI().toString());
with
Image icon = new Image(getClass().getResource("/img/javafxlogo.png"));
Now I get the error:
java: no suitable constructor found for Image(java.net.URL)
constructor javafx.scene.image.Image.Image(java.lang.String) is not applicable
(argument mismatch; java.net.URL cannot be converted to java.lang.String)
constructor javafx.scene.image.Image.Image(java.io.InputStream) is not applicable
(argument mismatch; java.net.URL cannot be converted to java.io.InputStream)
constructor javafx.scene.image.Image.Image(javafx.scene.image.PixelBuffer) is not applicable
(argument mismatch; java.net.URL cannot be converted to javafx.scene.image.PixelBuffer)
constructor javafx.scene.image.Image.Image(java.lang.Object) is not applicable
(Image(java.lang.Object) has private access in javafx.scene.image.Image)