Gwitninm Gwitninm - 1 year ago 69
Java Question

java BufferdImage dosen´t load

So right now I´m trying to load an Image on my Harddrive in a BufferdImage in my Code. Yet I think I did everything right but my trycatch only leaves the catch.

Code for better understanding :

private static BufferedImage image;

public void initPictures() {
try {
image = File("Pictures/blue.png"));
} catch (IOException ex) {
System.out.println("Will not load");


The initPictures() is called in my Constructor of the Class. And you can see here that my picture that I try to load is in the E:\Dropbox\Dropbox\Java Projekte\FallingBlocks1\build\classes\Pictures folder on my OS. So the "Pictures/blue.png" should be good.

Windows Folder Picture:

enter image description here

So my Qustion here is : What am I missing?

EDIT : added ex.printStackTrace(); nothing changed thought.

EDIT : also tried to load other pictures int the "image", with no other results

Answer Source

There are two possibilities:

1. Your program may not be running in the folder that contains the "Pictures" folder.

To find out where your program is running, do a System.out.println(System.getProperty("user.dir")); to see what folder you're running in. If it prints something other than E:\Dropbox\Dropbox\Java Projekte\FallingBlocks1\build\classes, you know it's an issue with the path you're providing to For kicks, you may also want to see what new File("Pictures/blue.png").isFile() is returning.

2. Your image might not readable.

If you try the first test out and you know for certain that the path you are providing is correct, then it's likely that your image file is either corrupt or cannot be read (could be caused by access restrictions, connectivity problems, hardware issues, etc.). Try pointing to a different image and see what happens.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download