带有Eclipse的Java类getResource() [英] Java class getResource() with eclipse

查看:152
本文介绍了带有Eclipse的Java类getResource()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力使getResource整个上午都能正常工作,但到目前为止,我必须使其正常工作的唯一方法是将res文件夹移到bin文件夹,然后像这样使用getResource

i've been trying to get getResource to work correctly this whole morning but so far the only way i've had to get it working is by moving the res folder to the bin folder and then using getResource like so

URL url = MyClass.class.getResource("/res/gfx/entity/entity1.png");

但是我没有办法使res不在bin文件夹中吗?

But is there not any way i can make it so res is outside the bin folder?

推荐答案

没关系,我真不敢相信那是多么愚蠢的修复程序.

Nevermind, i can't believe how stupid of a fix that was.

我将res文件夹添加到了主项目文件夹中,而不是bin中,然后进入了Eclipse

I added the res folder to the main project folder rather than bin, then went in eclipse

运行>运行配置>类路径>选择用户条目>高级>添加文件夹>选择res

run > run configurations > classpath > select user entries > advanced > add folders > select res

然后,当从res调用文件夹时,而不是执行"/res/gfx/entity/entity1.png",而是执行"/gfx/entity/entity1.png"

then when calling a folder from res, rather than doing "/res/gfx/entity/entity1.png", i did "/gfx/entity/entity1.png"

问题解决了!

这篇关于带有Eclipse的Java类getResource()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆