I'm having an odd problem. I have a game of sorts where an image bounces around the screen in 'darkness' (black Rect
) and the mouse cursor represents a flashlight shining through the dark (subtracts an oval).
Now I have one .png
image and one .wav
sound file. I have them both in a "resources" folder in my project folder and I access them via the filepaths "resources/myImage.png"
and "resources/mySound.wav"
.
Everything works fine when I run the program in Eclipse (using Kepler btw); the image shows up fine, and the sound plays when commanded to, but as soon as I export it as a jar and run, it shows the program name for a few seconds as if it were an active program, but shortly after quits/crashes. I open Terminal and run java -jar /Users/MyUsername/Desktop/MyProg.jar
which garners the same result but I get by crash log in Terminal. It reads:
Aug 23, 2013 4:10:02 PM com.spotlight.TestPane <init>
SEVERE: null
javax.imageio.IIOException: Can't read input file!
at javax.imageio.ImageIO.read(ImageIO.java:1301)
at com.spotlight.TestPane.<init>(TestPane.java:62)
at com.spotlight.Spotlight$1.run(Spotlight.java:32)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:691)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.spotlight.TestPane.<init>(TestPane.java:69)
at com.spotlight.Spotlight$1.run(Spotlight.java:32)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:691)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.spotlight.TestPane.move(TestPane.java:169)
at com.spotlight.TestPane$1.actionPerformed(TestPane.java:51)
at javax.swing.Timer.fireActionPerformed(Timer.java:312)
at javax.swing.Timer$DoPostEvent.run(Timer.java:244)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:691)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
For refence, my code for reading the image file is:
BufferedImage img;
//...
try {
img = ImageIO.read(new File("resources/myImage.png"));
} catch (IOException ex) {
Logger.getLogger(Spotlight.class.getName()).log(Level.SEVERE, null, ex);
}
The way I exported my program is as follows:
- I right-click on my project folder and select "Export"
- I select the "Runnable Jar" option
- I select the correct Launch Configuration
- I browse to the correct export destination (/Users/MyUsername/Desktop/MyProg.jar)
- Under "Library Handling," I choose "Extract required libraries into generated JAR"
- "Save as ANT script" remains unchecked
- I click "Finish," and the jar generates without any warnings
I know SO isn't really for posting crash logs, but I'm sorta stumped here, so any help is appreciated.
UPDATE:
I added a System.err.println
statement in the try/catch
block, and used Unarchiver to extract the jar's contents and the resources folder doesn't appear. If the resources aren't exporting, that might be my problem, but I don't know how to fix it.