是否将其复制到构建代码的任何地方?作为一个在
src目录没有帮助,如果在执行时类是在
bin目录(或jar文件)。
另请注意,如果您的课程在一个包中,则
Class.getResource默认情况下它将相对于该包起作用。因此,如果您的包是foo.bar,它将在寻找
foo/bar/resources/pracs/neko/whatever。如果要使其绝对,则可以使用
ClassLoader.getResource,也可以
/在字符串的开头放置前导:
String resource = String.format("/resources/pracs/neko/%s", nekosrc[i]);nekoPics[i] = tk.getImage(getClass().getResource(resource));要么
String resource = String.format("resources/pracs/neko/%s", nekosrc[i]);nekoPics[i] = tk.getImage(getClass().getClassLoader().getResource(resource));当然,如果
reousrces目录 实际上是 相对于您的软件包的,则不应这样做:)



