It works when I move the res folder inside the bin folder, although I've had issues doing it that way in the past where the folder has been wiped.Is this a poor project structure and if so, could somebody explain to me what a good structure would be and also why this is producing an error?

You're going through the classloader (as you should) to get the resource, so your path is already absolute -- those extra "../" segments are doing nothing but adding confusion. Next, make your res folder a source folder, and it will be copied into bin on build as a new root (don't use "res/" in the path). Once you've done that and told eclipse to build, you should be able to do this:

getClass().getClassLoader().getResourceAsStream("spriteSheet.png");

Last, Don't ever screw with the bin/ folder directly. Only eclipse should ever touch that -- you should be able to delete the entire bin/ folder at any time and let eclipse rebuild it.

...also we've found that making /res a source folder means that Eclipse in its wisdom copies the contents of /res into /bin, which can lead to very strange bugs when for whatever reason the contents of /bin are not quite up to date. So what we do nowadays is we add /res in the launch classpath instead.

I would really be interested in seeing code that replicated the issue of a user-defined class not having access to user-defined resources if no untoward monkeying around with the thread's CCL has taken place. Maybe some applet environments do exactly such tomfoolery, but I'd still like to see it.

As for copying into /bin, that's usually not a problem, and it means whatever jar you pack will guaranteed have those resources in them with no extra step needed. I guess it's different for games with large assets or lots of them.

...also we've found that making /res a source folder means that Eclipse in its wisdom copies the contents of /res into /bin, which can lead to very strange bugs when for whatever reason the contents of /bin are not quite up to date. So what we do nowadays is we add /res in the launch classpath instead.

Cas

Thanks for the trick, it's always bothering me to refresh my project each time I touch a resource file

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org