So I am trying to load a .png file for a very simple game. I have my all of my code saved in the directory: "C:\Users\Zach\Desktop\TestGame\source", and my image that I'm trying to load in a directory called "C:\Users\Zach\Desktop\TestGame\images". To load the image i am using

ImageIcon ii = new ImageIcon(this.getClass().getResource("..\\images\\right3.png"));

I used the ".." to move up one directory where the images directory is, and I am on a Windows machine so I was told to use the "\\" as a file separator character. However when I try to run the program I get a nullpointerexception. How could I fix this problem? Thanks in advance.

Try copying the image file to all the possible places that your getResource could refer to until the image is found. Then remove them one by one until it is not found.
The last removal will be where the code is looking.

Or separate the code that gets the URL from the ImageIcon constructor to a separate variable and print out its value to see where it is looking.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.