Eclipse -> Export to JAR | Images don't load?

Hello everyone! o/ I hope I'm in the right category. Well, I have a problem with my exported JAR file. I load some Images with PApplet.loadImage(). In eclipse it works without problems. But if I try it to export them into a JAR file, I got some exceptions.

My project structure:

Well, I load the Images from my with PApplet.loadImage("img/galaxy.gif") for example. It works in eclipse, but if I try it to export them to a JAR file and run it after, it gives me some exceptions:

java.lang.NullPointerException at processing.core.PApplet.dataFile( at processing.core.PApplet.dataPath( at processing.core.PApplet.createInputRaw( at processing.core.PApplet.createInput( at processing.core.PApplet.loadBytes( at processing.core.PApplet.loadImage( at processing.core.PApplet.loadImage( at make.object.Background.setup( at make.Applet.setup( at processing.core.PApplet.handleDraw( at processing.awt.PSurfaceAWT$12.callDraw( at processing.core.PSurfaceNone$

Well, this line here: at make.object.Background.setup(

It tells me it can't find any images. I had check my JAR file and the structure looks okey. I have my img folder here, my make folder (with the other stuff inside) and the imported core library. But why it doesn't load my images now?

Sorry for my bad english. I hope you understand my problem. ^^


  • Well, I find a solution for everyone who have this problem too. I added a static method to one of my classes:

    public static PImage getImage(String url) throws Exception { BufferedImage image =; return new PImage(image); }

    I use the class loader instead PApplet.loadImage() - For anyone who want to use this variant > add a "/" to the front of your path. In my case: "/img/galaxy.gif".

    But the question is the same: Why loadImage() don't work here? Or how I need to change it, that it works?

  • edited December 2017

    I'd give you the same tip I just did below today:

    PApplet.println(applet.dataPath("") + '/'));

  • edited December 2017

    Well, that don't work really well. It forces me to some special prject structure. First of all I need to import the processing library completly in my project as copy (I just added a reference to them in my file system). The second thing is, that I need to create a data Folder outside of my project (the src folder). But if I export the project as JAR, eclipse don't create me a data folder because it's not in my src folder. Instead I got my images in the root archiv (or the jar archiv itself):

    Well, a other problem is that eclipse can just find the images, if I use this kind of a file path: PApplet.dataPath("") + "/src/galaxy.gif")

    but in the exported JAR file isn't a src folder anymore. The question is, how I deal with it? The documentation from Processing tells me not to use new PImage and not to use dataPatch or sketchPath. And loadImage isn't obvious working. What is now the right solution?

  • edited December 2017 Answer ✓

    Well, I had some troubles with the alpha channel on my first solution. The *.gif images showed me a white background for the transparent. I changed something for my method:

    public static PImage getImage(String url) throws IOException {
            BufferedImage bi =;
            PGraphics g = applet.createGraphics(bi.getWidth(), bi.getHeight());
            Graphics2D g2d = (Graphics2D) g.getNative();
            g2d.drawImage(bi, 0, 0, bi.getWidth(), bi.getHeight(), null);
            return g.copy();

    Well, this works fine for me. I had look up in the source code from precessing and figured out that they don't load the images over the classpath. Well, I hope this help someone. Ah, before I forget it, it don't work in the FX2D mode. So be carefull.

  • edited February 2018

    Hey! I have this problem similar to yours. Would like to ask if you can explain a bit more about a static method. How I should use it in exactly?

    public static PImage getImage(String url) throws Exception{
        BufferedImage image ="assets/vase.jpg"));
        return new PImage(image);
    public void setup(){
        img = loadImage(("assets/vase.jpg"));
        img.resize(400, 0);
        // Create a new empty image;
        resultImg = createImage(img.width, img.height, PConstants.RGB);

    I tried to called in around this code but did not work!?

    Right now, the picture is called fine in Eclipse environment but with export to jar it could not find the image. So I'm trying to write the correct path to the file for jar.

Sign In or Register to comment.