0

我的代码在 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 中运行得非常好。

4

1 回答 1

0

好吧,我找到了问题的答案,我将“ File.separator”作为图像文件的名称传递,导致它找不到资源,所以我将其更改为“ /”,它在 eclipse 和 java 中再次开始正常工作网络开始

于 2012-10-03T20:12:34.447 回答