Java class getResource() with eclipse
Asked Answered
P

2

6

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");

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

Prober answered 9/9, 2012 at 17:39 Comment(0)
P
15

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

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

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

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

Problem solved!

Prober answered 9/9, 2012 at 18:2 Comment(2)
You are what they call a freaking genius! I've been pondering on the same problem for the past 30 minutes and it was driving me insane!!!Flagging
You actually saved a day (actually 2 days and 1 night I was stuck with the null error) by providing this solution.Headmaster
O
3

Normally, in a Java project, you would add the /res folder as a source folder in the project settings.

In a Plugin project, you would add the folder to the output in the build.properties.

In a Dynamic Web project, you would put the /res folder in the WebContent folder.

Outturn answered 9/9, 2012 at 17:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.