java获取不了图片路径
我是搞c#,公司需要修改个java项目,被逼上阵,遇到了个问题,卡了1天 ,查了很多资料,环境变量什么都配置了,小弟无法解决了,只能求助了,问题是获取不到图片路径
icons/man.png
Uncaught error fetching image:
java.lang.NullPointerException at sun.awt.image.URLImageSource.getConnection(Unknown Source)
at sun.awt.image.URLImageSource.getDecoder(Unknown Source)
at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source)
at sun.awt.image.ImageFetcher.fetchloop(Unknown Source)
at sun.awt.image.ImageFetcher.run(Unknown Source)[code=Java][/code]
代码
Java code
public ImageIcon getImageIcon(String image) {
System.out.println(path+image);
return new ImageIcon(Toolkit.getDefaultToolkit().getImage(
this.getClass().getClassLoader().getResource("icons/"+image)));
}
------解决方案--------------------
icons路径在哪里,跟src什么关系。