Examples don't find Monkey.jpg

Hello everyone, a Java newboy here  :?

While trying the jME examples I’ve noticed that the Monkey.jpg texture fails to load.

The HelloStates example trys to get it from:


The absolute path is:


I was going to try a solution from another jME forum post:

use something like:

File file = new File("/jmetest/data/images/Monkey.jpg");

URL monkeyLoc = file.toURL();

…but it turns out file.toURL() was deprecated at some point and, as I get an error with this, I assume now removed from the latest version of Java (which I’m using). I also assume that jME is able to do this and that I have some setting or something wrong (i.e. that I should not need to modify the example).

In case it helps: I’m using Windows 7 (64 bit), Java 6 (32 bit - have tried the 64 bit version too), Eclipse (not sure what Java version but downloaded in the last few days), JME 2.01 stable.

Offending console output:

WARNING: Could not load image…  URL was null. defaultTexture used.

I’m coding my examples to be stored in:


The only other problem I keep having is that with every example I create I need to tell it where the lwjgl platform stuff is located (in case this helps point to a path issue). I assumed I’d only need to edit the jME settings in one place to do this.

I also tried debugging into

URL monkeyLoc = HelloKeyInput.class.getClassLoader().getResource(

but the debugger does not trace into getResource() etc. (so I guess I’d need a different jME to do this), however, I am still thinking there’s some very simple mistake I must have made and that tracing into jME stuff should not be necessary.

As I mentioned, I am a Java novice. What daft mistake am I making?

Thank you.

I also tried adding 1 to 6 "…/" to the path and non of these worked.

Presumably the


will start looking from the


directory (so I should not need any "…/" to make it go up any directories)?

So far as I know my use of the workspace is the default and would assume this should be working…

My HelloKeyInput stuff is in:


which also as these subdirectories in it:




Let me know what you think?


HelloKeyInput.class.getClassLoader().getResource() will load from the binary folder of the project for which the HelloKeyInput class is belongs, if that makes any sense?

Make sure you use a class from the jME project, and you shouldn't have any trouble. :wink:

If everything else fails, you CAN use file.toURL(), even though its deprecated.

Good luck. :slight_smile:

  • Mikkel.

The absolute path is:

Thats strange, in my case the absolute path is:
Note: src not bin

I can reproduce your problem when I exclude the folder jmetest/data/images
from the source path in eclipse (right click on jme project -> Properties -> Java Build Path -> Source)

Make sure that jmetest.data.images shows up in eclipse in the project tree, just like all the other packages.
(That means it is included in the eclipse source path)

No need to use file.toURL()

PS: I asume you have checked out the JME source from SVN and your not using only 'binary' jars without source.

Mikkel, thanks for your reply.

I assume I must be using the jME stuff as I've not used Eclipse for anything else and I just copied the example source code into a new class file.

If everything else fails, you CAN use file.toURL(), even though its deprecated.

It's kind of like it has been removed (but perhaps I'm missing a trick) - V6 of Java. I got Eclipse to do all the imports it thought were needed but trying to use file.toURL() results in a compile error. Of course I guess I should not need to fiddle with the example if everything is set up correctly (unless getResource() uses file.toURL() and it really has been removed).

Larynx, thanks for your reply too.

I see that I do indeed have the same relative directory that you mention too which for me is:


I also tried this:


I tried giving this absolute path to no avail. The image is in all 3 places.

The example code from the jME site uses:


I originally installed jME via SVN and I couldn't get it to work (tried following various tutorials). I then downloaded jME2_0_1-Stable.zip and managed to get things "working" with that. Perhaps I've mucked something up by doing this?

This jME2_0_1-Stable.zip does have some .java files in it but I am not sure if this is everything (26M download).

I have tried adding a path to the image directory and it still does not pick it up (and I even loaded the image into photoshop to make sure it's not a duff .jpg and it works properly).

Quite frustrated with this but still sure it must be a simple thing I've not done properly.

All suggestions most welcome…

I would really suggest that you checkout the jme source via SVN.

If you have jme setup and compiling in eclipse you can run the examples directly from the jme project tree.

(im sure you will get help to get it running here)

If that works, then you can create your own project and link jme into your project.

(right click on your project -> Properties -> Java Build Path ->Projects -> add jme)

OK, some progress (of sorts).

(in case it helps, the example code I am trying to get working is HelloKeyInput).

I replaced:

// Point to the monkey image

URL monkeyLoc = HelloKeyInput.class.getClassLoader().getResource(



File file = new File("/Users/Kevin/workspace/jme/bin/jmetest/data/images/Monkey.jpg");

URI uri = file.toURI();

URL monkeyLoc = null;

try {

monkeyLoc = uri.toURL();

} catch (MalformedURLException e1) {

// TODO Auto-generated catch block



This does work (but, unlike some suggestions I could not go direct from file to URL, I had to convert to URI before I could convert to URL and I seemed to have to have the try/catch block in place - perhaps that’s just a java requirement). Perhaps needing to go via URI is me being a noob or perhaps it’s to do with Java 6.

This directory also works in the URI code above:

//works File file = new File("/Users/Kevin/workspace/jme/src/jmetest/data/images/Monkey.jpg");

The original path from the sample code does not work in the URI snippet:

//bad File file = new File(“jmetest/data/images/Monkey.jpg”);

I still do not think I should need to fiddle with the example source and I have something wrong. I am concerned that this issue will just propagate in to some kind if nightmare with the later, more involved, examples and I will eventually hit a real brick wall. I really would like to find out what I have done wrong so I use the example as intended.

More progress:

I used the original path:

//bad File file = new File(“jmetest/data/images/Monkey.jpg”);

and it generates this handy information in the exception output:


Now I can see that it is just appending the relative path on to my project path which is the wrong thing to be happening.

If this is what


does then that too will be wrong (although getResource() does not work with viable absolute paths either).

Does this help anyone to identify the issue?

Your research progress sheds some light on the problem.

For me it seems that the HelloKeyInput class is in your own eclipse project, because you copied it.

(It is still in jme, too - but yours gets loaded)

I googled a bit to find out what .class.getClassLoader().getResource() really does

(didnt know up until now, i just used it  :smiley: )

.class.getClassLoader().getResource(<subpath>) searches the classpath and checks if subpath

exists there. So theoretically it should work, because /Users/Kevin/workspace/jme/bin 'should' be

in your classpath, or else nothing jme would work i asume.

So as Mikkel said:

HelloKeyInput.class.getClassLoader().getResource() will load from the binary folder of the project for which the HelloKeyInput class is belongs, if that makes any sense?
Make sure you use a class from the jME project, and you shouldn't have any trouble. Wink



because SimpleGame 'must' be in your classpath and is a jme class and its unlikely that you have a class
of the same name in your project

Things have regressed  :frowning:

I decided to clear out the jME stuff and get it from SVN, as larynx suggests.

In almost the last step at


it says (in "Resolving the Build Path Issues")

swt.jar: do the same here but go to jme/lib/swt/<os>  to get the native library location

This was fine for lwjgl but, annoyingly, there is no swt in the lib section to set the native library for.

I looked to see what SVN had grabbed in to the new jme directory there is a lib/swt directory (with the windows native location). There are no .jar files in the swt directory (is that important I wonder).

So now, before I can try


I need to sort that out (as jME no longer works). Arrrgh!

Thanks for your help so far... What foolish mistake have I made this time?

Perhaps things have not regressed quite so much as I thought. Although the jME project now shows lots of errors the sample code still compiles.

I tried (in my copy of HelloKeyInput example) the suggestion from larynx

URL monkeyLoc = SimpleGame.class.getClassLoader().getResource("jmetest/data/images/Monkey.jpg");

...but, this still results in no texture.

WARNING: Could not load image...  URL was null. defaultTexture used.

So I now assume that no swt which I assume is wrong?

And I still have no resolution to the not finding textures issue.

Any suggestion please?

Have you added the windows/swt.jar to the list of libraries in eclipse - jme properties - Java Build Path ?

(it seems no need to set the native path for swt, too, because there are native libs inside the platform swt.jar)

As far is i know it could be that you have to download the latest swt.jar for 64-Bit windows, but as your

using 32-bit java on 64-bit windows … hmmm  :?

(im completely 64bit on linux, so i cant help too much with windows)

What compile errors are you getting?

Why dont you use 64-bit java?

Seems 64-bit windows is harder to get running than 64-bit linux  :slight_smile:

I'm now running all 32 bit java + related stuff due to my perceived risk of potential issues when trying to get things working a few days ago… with having 64 bit java and 32 bit Eclipse (there's not a 64 bit version yet for Win) etc. etc. I now have 32 bit Java (on my "64" bit PC  :frowning: ), all 64 bit stuff removed!

This cut out a lot of errors (while still leaving the above swt problem): change the Java compiler (in jME properties->java Compiler), check "Enable project specific settings" and change "Compiler compliance level:" to 1.5

OK, I added a build path, as suggested by larynx, that has jme/lib/swt/windows and that certainly seems to clear up a fair number of problems but things like:

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;

all have the error that
the import org.eclipse can not be resolved

Things that still have problems:

The problems in all of these are most things with a mention of swt.

A quick search of "import org.eclipse can not be resolved" seems to indicate that the path still needs adding to the build path. Arrrgh!

After typing the above "Arrrgh!" I made more progress:

I had to go in to the jME properties->Java build Path->libraries
then press "Add external JARs..." and navigate down to the windows specific swt.jar file. All the other stuff had been there, why not this (I wonder)... I suspect this problem will come back to haunt the next person to try jME on a similar platform.

Now there are no errors in jME (lots of warnings).

Not much progress: :(
So now we're back to the original problem: the Monkey.jpg texture is not found.

And the problem seems to be exactly the same as before:
The same modified version where I added the working URI stuff works, nothing else tried does.

Any suggestions folks?
Now there are no errors in jME (lots of warnings).

I would call this a rather big step forward, you have just compiled jme successfully  :wink:

Pls try to run for example jmetest.TutorialGuide.HelloModelLoading directly from the jme tree.

This should display the face of maggie simpson.

I asume you have still references to the jme snapshot jars in your own project, thats why
i suggest to run the jme examples directly.

OK Larynx, nice one, thank you very much for your help.  :smiley:

It turns out that the old install of jME2.01-stable was still there (I had not installed it to my working directory and SVN one was). I deleted that old install. It then seemed to take a while for Eclipse to notice (i.e. before I could no longer see the references in my HelloKeyInput to the old jME stuff).

I tried the build in test, as you suggested, (with the Simpsons - Maggies face) demo and that worked fine.

I then deleted my old HelloKeyInput project and redid it, this time making sure that it was picking up the new jME stuff and it works like a treat.

I now AM "Captain Happy". Thank you so much for your help.

Im glad to hear that its working now and i was able to help  :lol:

Also i have learned something, too.

getResource() is looking at the classpath (param must be always relative),

as opposed to  'new File', when used with relative param, is from the project root directory.

Eclipse can be a beast to setup, but its a wonderful beast (just like opengl)  :smiley:

Now that its runnning you could look at jmetest.effects.water.TestProjectedWater.java

to relax and watch some really nice big waves  :wink: