java - Trouble reading BufferedImage -


i'm having odd problem. have game of sorts image bounces around screen in 'darkness' (black rect) , mouse cursor represents flashlight shining through dark (subtracts oval).

now have 1 .png image , 1 .wav sound file. have them both in "resources" folder in project folder , access them via filepaths "resources/myimage.png" , "resources/mysound.wav".

everything works fine when run program in eclipse (using kepler btw); image shows fine, , sound plays when commanded to, export jar , run, shows program name few seconds if active program, shortly after quits/crashes. open terminal , run java -jar /users/myusername/desktop/myprog.jar garners same result crash log in terminal. reads:

aug 23, 2013 4:10:02 pm com.spotlight.testpane <init> severe: null javax.imageio.iioexception: can't read input file!     @ javax.imageio.imageio.read(imageio.java:1301)     @ com.spotlight.testpane.<init>(testpane.java:62)     @ com.spotlight.spotlight$1.run(spotlight.java:32)     @ java.awt.event.invocationevent.dispatch(invocationevent.java:251)     @ java.awt.eventqueue.dispatcheventimpl(eventqueue.java:721)     @ java.awt.eventqueue.access$200(eventqueue.java:103)     @ java.awt.eventqueue$3.run(eventqueue.java:682)     @ java.awt.eventqueue$3.run(eventqueue.java:680)     @ java.security.accesscontroller.doprivileged(native method)     @ java.security.protectiondomain$1.dointersectionprivilege(protectiondomain.java:76)     @ java.awt.eventqueue.dispatchevent(eventqueue.java:691)     @ java.awt.eventdispatchthread.pumponeeventforfilters(eventdispatchthread.java:242)     @ java.awt.eventdispatchthread.pumpeventsforfilter(eventdispatchthread.java:161)     @ java.awt.eventdispatchthread.pumpeventsforhierarchy(eventdispatchthread.java:150)     @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:146)     @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:138)     @ java.awt.eventdispatchthread.run(eventdispatchthread.java:91)  exception in thread "awt-eventqueue-0" java.lang.nullpointerexception     @ com.spotlight.testpane.<init>(testpane.java:69)     @ com.spotlight.spotlight$1.run(spotlight.java:32)     @ java.awt.event.invocationevent.dispatch(invocationevent.java:251)     @ java.awt.eventqueue.dispatcheventimpl(eventqueue.java:721)     @ java.awt.eventqueue.access$200(eventqueue.java:103)     @ java.awt.eventqueue$3.run(eventqueue.java:682)     @ java.awt.eventqueue$3.run(eventqueue.java:680)     @ java.security.accesscontroller.doprivileged(native method)     @ java.security.protectiondomain$1.dointersectionprivilege(protectiondomain.java:76)     @ java.awt.eventqueue.dispatchevent(eventqueue.java:691)     @ java.awt.eventdispatchthread.pumponeeventforfilters(eventdispatchthread.java:242)     @ java.awt.eventdispatchthread.pumpeventsforfilter(eventdispatchthread.java:161)     @ java.awt.eventdispatchthread.pumpeventsforhierarchy(eventdispatchthread.java:150)     @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:146)     @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:138)     @ java.awt.eventdispatchthread.run(eventdispatchthread.java:91)  exception in thread "awt-eventqueue-0" java.lang.nullpointerexception     @ com.spotlight.testpane.move(testpane.java:169)     @ com.spotlight.testpane$1.actionperformed(testpane.java:51)     @ javax.swing.timer.fireactionperformed(timer.java:312)     @ javax.swing.timer$dopostevent.run(timer.java:244)     @ java.awt.event.invocationevent.dispatch(invocationevent.java:251)     @ java.awt.eventqueue.dispatcheventimpl(eventqueue.java:721)     @ java.awt.eventqueue.access$200(eventqueue.java:103)     @ java.awt.eventqueue$3.run(eventqueue.java:682)     @ java.awt.eventqueue$3.run(eventqueue.java:680)     @ java.security.accesscontroller.doprivileged(native method)     @ java.security.protectiondomain$1.dointersectionprivilege(protectiondomain.java:76)     @ java.awt.eventqueue.dispatchevent(eventqueue.java:691)     @ java.awt.eventdispatchthread.pumponeeventforfilters(eventdispatchthread.java:242)     @ java.awt.eventdispatchthread.pumpeventsforfilter(eventdispatchthread.java:161)     @ java.awt.eventdispatchthread.pumpeventsforhierarchy(eventdispatchthread.java:150)     @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:146)     @ java.awt.eventdispatchthread.pumpevents(eventdispatchthread.java:138)     @ java.awt.eventdispatchthread.run(eventdispatchthread.java:91) 

for refence, code reading 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 exported program follows:

  • i right-click on project folder , select "export"
  • i select "runnable jar" option
  • i select correct launch configuration
  • i browse correct export destination (/users/myusername/desktop/myprog.jar)
  • under "library handling," choose "extract required libraries generated jar"
  • "save ant script" remains unchecked
  • i click "finish," , jar generates without warnings

i know isn't posting crash logs, i'm sorta stumped here, appreciated.


update: added system.err.println statement in try/catch block, , used unarchiver extract jar's contents , resources folder doesn't appear. if resources aren't exporting, might problem, don't know how fix it.

common problem commonly posted here. you're trying access resource file no file exists. stop. jar files don't hold files, don't try access in them files. data resource instead. google issue because said, posted here several times week.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -