Could not load image... URL was null

why is curasorLoc always null? I have tried a few things. Please Help. Her is the code:



protected void simpleInitGame() {

// Create a new mouse. Restrict its movements to the display screen.

am = new AbsoluteMouse("The Mouse", display.getWidth(), display.getHeight());

// Get a picture for my mouse.

TextureState ts = display.getRenderer().createTextureState();

cursorLoc = getClass().getClassLoader().getResource("/jmetest/data/cursor/cursor1.png");

// cursorLoc = HelloMousePick.class.getClassLoader().getResource("test.png");

// cursorLoc = HelloMousePick.class.getClassLoader().getResource("/testbuild/jmetest/data/cursor/cursor1.png");

// Texture t = TextureManager.loadTexture(cursorLoc,Texture.MM_LINEAR,Texture.FM_LINEAR, true);

Texture t = TextureManager.loadTexture(cursorLoc,Texture.MM_LINEAR,Texture.FM_LINEAR);

ts.setTexture(t);

am.setRenderState(ts);

//



and here is the error:

C:jme>java -Djava.library.path=C:lwjgl-win32-0.96native -cp C:myProjectsHel

loMousePickdistHelloMousePick.jar;C:jmetargetjme.jar;C:lwjgl-win32-0.96ja

rlwjgl.jar HelloMousePick

May 8, 2005 6:06:40 PM com.jme.app.BaseGame start

INFO: Application started.

May 8, 2005 6:06:40 PM com.jme.system.PropertiesIO <init>

INFO: PropertiesIO created

May 8, 2005 6:06:40 PM com.jme.system.PropertiesIO load

INFO: Read properties

****** here ********

May 8, 2005 6:06:52 PM com.jme.system.lwjgl.LWJGLDisplaySystem <init>

INFO: LWJGL Display System created.

May 8, 2005 6:06:52 PM com.jme.system.PropertiesIO save

INFO: Saved properties

May 8, 2005 6:06:52 PM com.jme.system.lwjgl.LWJGLDisplaySystem <init>

INFO: LWJGL Display System created.

May 8, 2005 6:06:55 PM com.jme.renderer.lwjgl.LWJGLRenderer <init>

INFO: LWJGLRenderer created. W: 800H: 600

May 8, 2005 6:06:55 PM com.jme.renderer.AbstractCamera <init>

INFO: Camera created.

May 8, 2005 6:06:55 PM com.jme.util.lwjgl.LWJGLTimer <init>

INFO: Timer resolution: 1000 ticks per second

May 8, 2005 6:06:55 PM com.jme.scene.Node <init>

INFO: Node created.

May 8, 2005 6:06:56 PM com.jme.scene.Node <init>

INFO: Node created.

May 8, 2005 6:06:56 PM com.jme.scene.Node attachChild

INFO: Child (FPS label) attached to this node (FPS node)

Could not load image… URL was null.

java.lang.NullPointerException

at com.jme.input.Mouse.setRenderState(Unknown Source)

at HelloMousePick.simpleInitGame(HelloMousePick.java:49)

at com.jme.app.SimpleGame.initGame(Unknown Source)

at com.jme.app.BaseGame.start(Unknown Source)

at HelloMousePick.main(HelloMousePick.java:36)

May 8, 2005 6:06:56 PM com.jme.app.SimpleGame cleanup

INFO: Cleaning up resources.

May 8, 2005 6:06:56 PM com.jme.app.BaseGame start

INFO: Application ending.

Couple things to check:


  1. remove the first ‘/’
  2. make sure cursor1.png exists in the directory you are pointing to (especially capitalization, i.e. is it cursor1.PNG?)
  3. if you are running the app in: C:game, then according to your code there should be a C:gamejmetestdatacursor directory. Is this true?
  4. How are you running it? For instance, in eclipse, you must refresh the project if you add an image to the directory structure it’s handling.

I have tried the path with and without the leading "/".



I have the case right. I am runnin from the c:jme directory. The sample code from starter.pdf is:

cursorLoc =HelloMousePick.class.getClassLoader().getResource("/jmetest/data/cursor/cursor1.png");



but the dir structure is testbuild/jmetest/data/cursor/cursor1.png I have tried placing the png in c:jme and other places none work.



I am developing in netBeans 4.0 I have the same error runnin in netBeans and at the DOS prompt.



Where should the png file be placed? This the sample HelloMousePick from starter.pdf



Thanks for the quick responce mojo.

In NetBeans 4.0 it’s very important to put a main class for your project if you use the getRessource() Method (even if you have many classes with main() in your project, you must choose one, because it defines the root path).



Try this :



right click on your project folder in the project window

select properties

select “running file”

fill the “main class” field with the main class you want

retry



Hope that helps,



Adenthar