java - getImage() throws exception on commandline but not in eclipse? -


i'm loading images using following function:

public static image loadimage(string path){         log.debug("loadimage> path: "+path);         return toolkit.getdefaulttoolkit().getimage(clientapp.class.getclassloader().getresource(path));     }  utils.loadimage("images/carrot_stage_0.png") 

this function throws nullpointerexception when package jar , run command line:

          - loadimage> path: images/carrot_stage_0.png java.lang.nullpointerexception         @ sun.awt.suntoolkit.getimagefromhash(unknown source)         @ sun.awt.suntoolkit.getimage(unknown source)         @ com.tate.world.client.utils.loadimage(utils.java:11)         @ com.tate.world.client.carrot.<init>(carrot.java:24)         @ com.tate.world.client.inventory.<init>(inventory.java:32)         @ com.tate.world.client.drawpanel.<init>(drawpanel.java:35)         @ com.tate.world.client.clientframe.doinit(clientframe.java:46)         @ com.tate.world.client.clientapp$1.run(clientapp.java:18)         @ java.awt.event.invocationevent.dispatch(unknown source)         @ java.awt.eventqueue.dispatcheventimpl(unknown source)         @ java.awt.eventqueue.access$500(unknown source)         @ java.awt.eventqueue$3.run(unknown source)         @ java.awt.eventqueue$3.run(unknown source)         @ java.security.accesscontroller.doprivileged(native method)         @ java.security.protectiondomain$javasecurityaccessimpl.dointersectionp rivilege(unknown source)         @ java.awt.eventqueue.dispatchevent(unknown source)         @ java.awt.eventdispatchthread.pumponeeventforfilters(unknown source)         @ java.awt.eventdispatchthread.pumpeventsforfilter(unknown source)         @ java.awt.eventdispatchthread.pumpeventsforhierarchy(unknown source)         @ java.awt.eventdispatchthread.pumpevents(unknown source)         @ java.awt.eventdispatchthread.pumpevents(unknown source)         @ java.awt.eventdispatchthread.run(unknown source) 

but doesn't throw same exception when run ide eclipse.

it first didn't make sense , thought code wrong, after trying many variations checked if image available. turned out filename wrong, used "carrot_stage_0.png" in classpath names "carrots_stage_0.png". after corrected it started working.

but raises question why following code doesn't throw kind of exception when image, being loaded, can't loaded (in eclipse). throw nullpointerexception on command line.

toolkit.getdefaulttoolkit().getimage(clientapp.class.getclassloader().getresource(path) 

(same java 8 versions used)

it puzzles me :-)


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -