Is the image file on the classpath?
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
Sorry, I don't use Netbeans.
Put it all in a jar file and see it that works.
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
didn't work
Errors?
What is in the jar file? Did you put the images in there also?
Are there any error messages if you execute the jar file in a command prompt window?
If so, copy and paste them here.
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
why would running it as a jar be any different than running the project as normal?
There wouldn't be an IDE involved.
Add some debugging code to your program to test if the image is loaded OK. For example:
println("image1=" + startBackground);
and
println("image2=" + startBackgroundi);
Then run it from the jar and see what is printed on the console.
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
It looks like your program is not finding the image file. The getResource() method is returning null.
Where is the image file its trying to find?
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
the image is in the same folder as this file.
What file is "this file"?
have you tried executing the program from a command prompt window?
Open a window and change directory to get to the folder with the class files and the image file. Enter the command:
java NameOfClassWithMainMethod
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
Don't know why but getImage() works for me vs using createImage()
NormR1
Posting Expert
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656