0

this is my first time asking a question on here but I have no where else to go, I've searched online but I can't seem to find an answer to my problem

I'm trying to simply load an image into an ImageView using javaFX on netbeans

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.stage.Stage;

public class ImageTest extends Application {

@Override
public void start(Stage primaryStage) {
    Image image = new Image(getClass().getResourceAsStream("wall.jpg"));
    ImageView iv = new ImageView(image);
    Group root = new Group(iv);

    Scene scene = new Scene(root, 300, 250, Color.WHITE);

    primaryStage.setTitle("Hello World!");
    primaryStage.setScene(scene);
    primaryStage.show();
}

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

}

This code was my test run to see if that "wall.jpg" image would load in a different class, but no matter what I do it still throws an error. I've tried multiple other images but none seem to work. All the files are in the same folder with the code so I'm not quite sure whats going wrong here

kozmo
  • 4,024
  • 3
  • 30
  • 48
  • 2
    "It throws an error". Did you read the [stack trace](https://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors) and try to figure out what was wrong? You need to post that here in its entirety if you are unable to understand it and need help. If the issue is the location of the image file, you will also need to post your project layout. – James_D Feb 02 '18 at 00:31
  • Please add the error(s) you are seeing to your post. – casieber Feb 02 '18 at 00:41
  • Either you could have the wrong path (check the many other similar questions regarding getResAsStream) or the image is not in your build directory. Are you using maven by any chance? – DPM Feb 02 '18 at 00:59

0 Answers0