Resource Loading Oddness

Okay all.  This may end up being a noob question, but I am pretty confused.  I have been pouring over the tutorials getting a feel for jME structure and I was messing around with HelloTerrain.java.



Concerning this code:


        URL grayScale=HelloTerrain.class.getClassLoader()
                                  .getResource("jmetest/data/texture/bubble.jpg");



I desided to switch it up and alter the terrain a bit.  I fired up photoshop, opened bubble.jpg and pasted in a chunk grayscale image i got off the usgs website.  Saved it and launched HelloTerrain again.

... no change in the terrain at all.  Hrm, Oddness.
So I searched my computer for any other 'bubble.jpg' and found that there are only two on my computer:

C:Documents and SettingsdaveMy DocumentsJava Workspacesjmebinjmetestdatatexturebubble.jpg
C:Documents and SettingsdaveMy DocumentsJava Workspacesjmesrcjmetestdatatexturebubble.jpg

At that point I didn't know where Eclipse was reading from, so I replaced both the bubble.jpgs with my new data.  Lanuched HelloTerrain again.... still no change in the terrain at all.  Oddness.

Then I up and deleted all bubble.jpgs from my computer and launched HelloTerrain one more time... without errors, launched just fine and showed the original terrain... no changes.  Oddness.

I tried copying bubble.jpg to myterrain.jpg and changing the code to:

        URL grayScale=HelloTerrain.class.getClassLoader()
                                  .getResource("jmetest/data/texture/myterrain.jpg");



which results in the tutorial failing to start with the error:

SEVERE: Exception in game loop
java.lang.NullPointerException
   at javax.swing.ImageIcon.<init>(Unknown Source)
   at stdGame01.HelloTerrain.complexTerrain(HelloTerrain.java:58)
   at stdGame01.HelloTerrain.simpleInitGame(HelloTerrain.java:39)
   at myGameStruct.MyBaseSimpleGame.initGame(MyBaseSimpleGame.java:467)
   at myGameStruct.MyBaseGame.start(MyBaseGame.java:31)
   at stdGame01.HelloTerrain.main(HelloTerrain.java:33)
Dec 7, 2007 11:12:43 AM myGameStruct.MyBaseSimpleGame cleanup




Lastly, in Eclipse I used Project->Clean and cleaned ALL projects.  Still same behavior.

I understand that Eclipse might be caching something, but I do not understand where the tutorial is loading bubble.jpg from!

...any ideas?



I bet Eclipse is accessing that resource from a JAR file!

You have to refresh your project if you change files this way. Select your project and hit F5 that's it.

A second stupid thing I found: Normally eclipse copies all files from src to bin. But if you change only the file in src the old file in bin-folder will be used. So copy a new version of a file always to both folders and remember to refresh.

Izibaar:  Refreshing isn't working :frowning:



duenez:

How does one point the app to load off the OS's file system instead of a .jar?

Well, that depends on your configuration… The way to go is to right-click on your project, and go to Java Build Path and see if you have the jme'jar file selected there in libraries or projects. If so, you should really be accessing only the bin subdirectory of your jme directory instead of the jar file. (Note that some JAR files are pre-requisites for jME to run, don't remove those like lwjgl, jinput, etc).





Try this for both your project and your jME base project.



Hope you can find it.  :wink:

duenez said:

Well, that depends on your configuration... The way to go is to right-click on your project, and go to Java Build Path and see if you have the jme'jar file selected there in libraries or projects. If so, you should really be accessing only the bin subdirectory of your jme directory instead of the jar file. (Note that some JAR files are pre-requisites for jME to run, don't remove those like lwjgl, jinput, etc).


Try this for both your project and your jME base project.

Hope you can find it.  ;)


You rock.  :)  Worked like a champ!

I gave up on trying to use URLs when using jME from jars, and I'm instead using the String version of resource loading, which is a file path from the working directory.

jwatte said:

I gave up on trying to use URLs when using jME from jars, and I'm instead using the String version of resource loading, which is a file path from the working directory.


Any way you can post some linkage or code snippets?

        Texture tex = TextureManager.loadTexture("src/data/corrugated_combined.png", Texture.MM_LINEAR_LINEAR, Texture.FM_LINEAR);

        TextureState texSt = display.getRenderer().createTextureState();
        texSt.setCorrection(TextureState.CM_PERSPECTIVE);
        texSt.setEnabled(true);
        texSt.setTexture(tex);



This assumes you have a directory called "data" in your src directory, and that the working directory is the project directory (the directory contaning bin and src). If your IDE is not Eclipse, then the set-up may be different. Note that, if you ever create an installation of this executable, you have to create the directory src/data as part of the installer; it's not as nice as a URL in that you can re-direct it.

Btw: Eclipse is pretty nice! A lot better than NetBeans, which I used before to try some j2me stuff. I just wish there was an easy way to configure the hotkeys to work like MSVC...