eclipse3.1 + jdk 1.5 + swt designer 桌面应用程序开发
在eclipse中运行程序时 显示图片的位置正确
代码:
File aFile = new File(MySWTLiveNowMain_3.class.getResource("index_new.png").getPath());//
//String path = aFile.getAbsolutePath();
String path = aFile.getPath();但是把整个项目打成exe包运行后报错
“Caused by: java.io.FileNotFoundException: file:\C:\Documents%20and%20Settings\Administrator\Local%20Settings\Temp\e4j25.tmp_dir24260\Java_LiveNow.jar!\com\LiveNow\index_new.png (文件名、目录名或卷标语法不正确。)”
是说这个png图片不存在,可是打开这个相应路径下的包有这个png图片,到底是什么问题呢?

解决方案 »

  1.   

    你的图片路径都不对,可能在eclipse里显示的是 eclipse自己缓存的.
      

  2.   

    你没放对,和源文件一起。指定PACKAGE啊
      

  3.   

    这个问题不是图片路径的问题,而是把项目打成jar包后,再用第三方软件生成exe,java apliaction在运行的时候找jar包中的文件即使用绝对路径也识别不到的,所以此方法需要修改为:Image shellbackimage = SWTResourceManager.getImage(MySWTLiveNowMain_3.class, "/LiveNowimages/index_new.png"); 用此方法得到Image。