在Java Web Start下调用getResourceasStream()时代码卡住了

时间:2012-10-03 17:35:38

标签: java eclipse java-ee

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

1 个答案:

答案 0 :(得分:0)

我找到了问题的答案,我将“File.separator”作为图片文件的名称传递,导致它找不到资源,因此我将其更改为“/ “它开始在eclipse和java web start中再次完美地工作