我的代码在 Eclipse 中运行良好,但是当我尝试使用 Java web start 运行相同的代码时,它会自动终止并且无法调用getResourceAsStream()
方法。
这是代码
public ImageIcon loadImageIcon ( String name ) throws IOException, FileNotFoundException {
logger.info("entering resource loader class in loadimage icond method");
logger.info("object is "+this);
logger.info("class is "+this.getClass());
logger.info("class loader is "+this.getClass().getClassLoader()+" object trying to load is "+name);
InputStream in = this.getClass().getResourceAsStream( name ) ;
logger.debug("loadimageicon: loading image inside resource loader "+this.getClass().getResource(name).getPath());
ImageIcon returnImage = null ;
if ( in != null ) {
returnImage = new ImageIcon ( InputStreamLoader.load ( in ) ) ;
in.close() ;
} else
throw new FileNotFoundException ( name ) ;
return( returnImage ) ;
}
这是日志
[2012-10-03 13:15:03,015] [Thread-21] INFO com.test.nzna.shared.util.ResourceLoader - object is com.ibm.nzna.shared.util.ResourceLoader@1b7f958
[2012-10-03 13:15:03,015] [Thread-21] INFO com.test.nzna.shared.util.ResourceLoader - class is class com.ibm.nzna.shared.util.ResourceLoader
[2012-10-03 13:15:03,015] [Thread-21] INFO com.test.nzna.shared.util.ResourceLoader - class loader is com.sun.jnlp.JNLPClassLoader@1bf68a9 object trying to load is Default\logon.gif
我重复代码在 Eclipse 中运行得非常好。