While attempting to mess around with JavaFX and its basic functions on java 1.8 I kept running into the issue that my Image objects would not accept the URL for a png file contained within my src folder. The icon image object gave me trouble at first but when I copied the file name via the "Copy Path/Reference..." option it worked. This was not the case for the coinImage object where no matter how I format the image URL it will not accept it. To clarify, my files are named "icon.png" and "coin.png" and they are placed in the src folder. I have tried the following formats:
Image coinImage = new Image("coin.png");
Image coinImage = new Image("/coin.png");
Image coinImage = new Image("file:coin.png");
Image coinImage = new Image("file:/coin.png");
Below is the code which most relates to the problem to reduce on the size of this question:
public class MainStage extends Application {
public void start(Stage stage) throws Exception{
Group root = new Group();
Scene scene = new Scene(root,1000,1000,Color.LIGHTSKYBLUE);
Image icon = new Image("icon.png");
Image coinImage = new Image("coin.png");
ImageView imageView = new ImageView(coinImage);
imageView.setX(400);
imageView.setY(500);
root.getChildren().add(imageView);
stage.getIcons().add(icon);
stage.setTitle("Test");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Here are all of my imports as well but I do not think they are the issue here:
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.scene.shape.Polygon;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.Text;
import javafx.stage.Stage;
If any additional information is needed I should be able to provide it. Thanks.