loadImage does not Load Image from data folder

I am using the loadImage example, and definately have the image saved in the data folder of the active sketch.
Except for the web URL example below, I get the error message: “The file “moire.jpg” is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable. NullPointerException”

I suspect my path is wrong somehow, I have tried many more options than shown here.
I read that “the image file must be in the data folder of the current sketch.”
I quadruple checked & the image file is there in the data folder, and readable. Tried other file formats too.
Thanks in advance!

PImage img;
void setup() {
//img = loadImage("data/moire.jpg");  // does not work
// img = loadImage("moire.jpg");        // does not work
// img = loadImage("C:\Users\john\Documents\Processing\moire3\data\moire.jpg");   // does not work
// img = loadImage(" http://www.cosmation.com/images/cosmationpostcard2lowres.jpg");  //  this works
void draw() {
  image(img, 0, 0);

LoadImage or loadImage?

It should work even without specifying the path.

Your 3rd option (where you wrote out the full path) doesn’t work because you used backslash instead of a forward slash. backslash signals an escape sequence.

I don’t know how your files are set up but this probably means something is named incorrectly. Check that:

  1. The data folder is named correctly
  2. The file is named correctly (This is case sensitive)
  3. You have the correct file extension (.png, .jpg etc)

I know that you may have already done all this (and if that’s the case I’m probably just frustrating you :relaxed:) . If there are no other visible problems I would just try it with a different picture. Try to isolate where exactly is the problem.

Thanks for your help.
Things I’ve tried before asking for help: different images, different file formats, spelling & case options such as: PNG,JPG, TGA, . jpg, JPG, JPEG.
Recreated sketch, saved to new folder. Made data folder and added image manually.
Recreated sketch, saved to new folder. Dragged image to sketch. Processing made a data folder and added image to it.
Recreated sketch, saved to new folder. Used “add file” from sketch menu options. Chose image and saw that Processing made a data folder and added image to it.
I’ve specified the path, and not specified the path.
Only a lower case l in loadImage works. Not sure why theres a capital L in my code I shared.

saved and ran, same results. I agree something is off.
Will start over with yet another new / different image, and sketch.
Thanks for reviewing. Very helpful!

What editor are you using, and which platform?

Using Windows 10, the stock PGE editor. Java. Still wrapping my head around the P5.js

Issue resolved: Apparently it was windows (and my) foolishness.
I tried again tonight with new images and noticed none of my images had the file type extension showing.
I turned on “Show file name extensions”, and saw that my failing to load files had names like “moire.jpg.jpg”.
Yes, I had added the extension in myself in my hours of thrashing around. I am usually on a mac, and forgot that I did not have that display option enabled on this windows box. Thought that adding the extension would help, not knowing the extension was there, but just not being shown.
I removed the double extension and like magic, files were found, no errors.
Thanks for the advice and help.
Back to reading the manual!
Window setting: “Enable file name extensions” was part of the solution, showing I had added 2 extensions in my troubleshooting.
Johnny Why

1 Like

1st thing I do when I’m finished installing Windows is to check that option. :heavy_check_mark:

So many victims fell to files such as “moire.jpg.exe” when they just see “moire.jpg”. :see_no_evil: