Can't get Images to show up in javafx

I’m new to javaFx and I can’t seem to get these images to show up on a grid pane. Also I’m using intelliJ.

Here is my code 

package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import javafx.scene.layout.GridPane;

import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

import java.io.File;


public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{

        GridPane pane = new GridPane();

        //place pictures


        pane.add(new ImageView(new Image(new File("image/ca.gif").toURI().toString())), 0, 0);
        pane.add(new ImageView(new Image(new File("image/us.gif").toURI().toString())), 1, 0);
        pane.add(new ImageView(new Image(new File("image/uk.gif").toURI().toString())), 0, 1);
        pane.add(new ImageView(new Image(new File("image/china.gif").toURI().toString())), 1, 1);

        //create a scene and place it in the stage
        Scene scene = new Scene(pane);
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
        primaryStage.setTitle("images");
        primaryStage.setScene(scene);
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}

This is what I get when it runs 

This is what my paths look like 

Capture2.JPG

Did you try 

new Image("file:image/ca.gif")

as per the answer to this stack overflow question?

1 Like