java 引用资源-ClassLoader.getResource()方法

如图,eclipse中我的包结构为:,我在 spt.app.MainFrame 中可以通过一下代码段使用资源:

public static Object obj = ImageIconProxy.class.getClassLoader().getResource("img/absent.png");

但是我们不能在A类中,引用别的类声明类似上面的方法,例如,我们再 spt.proxy.ImageIconProxy 类中声明:

public static Object obj = ImageIconProxy.class.getClassLoader().getResource("img/absent.png");

然后再 spt.app.MainFrame 中引用:Object obj = ImageIconProxy.obj; //这样是无法获取到的.

posted @ 2014-12-24 01:00  wonkju  阅读(477)  评论(0编辑  收藏  举报