java - Executing jar issue - uncaught error fetching image -
i've made audio player , jar made netbeans. load images i've used:
classloader cl = this.getclass().getclassloader(); url playericonurl = cl.getresource("tp/audioplayer/images/icon.png"); if (playericonurl != null){ imageicon playericon = new imageicon(playericonurl); frame.seticonimage(playericon.getimage()); } else{ system.err.println("cannot load player icon"); }
i mention folder images in src/tp/audioplayer.
when i'm running application inside netbeans allright, when execute jar in command prompt,the application starts it's blank , blocks , get:
can tell me i've done wrong or problem? in advance!
try of these:
// using getresourceasstream inputstream = this.getclass().getresourceasstream( "picture.gif" ); // or inputstream = myclass.class.getresourceasstream( "stuff.ser" ); // or inputstream = myapp.class.getclassloader().getresourceasstream( "inwords.properties" );
the resource in jar file must qualified same package name class call getresourceasstream from. alternatively, can use absolute name beginning / dots mapped /s. if don’t have lead /, have relative name, , name of package prepended. if use /, must include name of package yourself, or whatever name resource filed under in jar. example specify /com/mindprod/mypackage/mystuff.ser or /com.mindprod.mypackage.mystuff.ser or mystuff.ser. don’t use windows style filenames . these not filenames, java resources live along class files either in jars or freestanding on disk, or on server.
in theory, getresourceasstream in local classpath, in jar , in directory class file loaded from.
Comments
Post a Comment