Unable to load images – jME2 tutorials

Hi,

I am very new to JMonkey and this is my first post here, hope this is the correct section

I tried 3 JMonker 2.1 tutorials so far. None of them loaded any images. I get following warning when I run in Lesson 2.

Jun 4, 2011 4:11:17 PM com.jme.util.TextureManager loadTexture
WARNING: Could not load image. Specified URL is null.
Jun 4, 2011 4:11:24 PM com.jme.app.BaseGame start
INFO: Application ending.

And in Lesson 3 following exception is thrown
Jun 4, 2011 4:18:22 PM class jme.test.Lesson3 start()
SEVERE: Exception in game loop
java.lang.NullPointerException
at javax.swing.ImageIcon.(ImageIcon.java:167)
at jme.test.Lesson3.buildTerrain(Lesson3.java:199)
at jme.test.Lesson3.initGame(Lesson3.java:151)
at com.jme.app.BaseGame.start(BaseGame.java:74)
at jme.test.Lesson3.main(Lesson3.java:62)
at jme.test.Main.main(Main.java:14)
Jun 4, 2011 4:18:22 PM com.jme.app.BaseGame start
INFO: Application ending.

This is the related code snippet
[java]// generate a terrain texture with 3 textures
ProceduralTextureGenerator pt = new ProceduralTextureGenerator(heightMap);
pt.addTexture(new ImageIcon(Lesson3.class.getClassLoader().getResource("/home/user/NetBeansProjects/Hello3D/images/grassb.png")), -128, 0, 128); //line 199
pt.addTexture(new ImageIcon(Lesson3.class.getClassLoader().getResource("dirt.jpg")), 0, 128, 255);
pt.addTexture(new ImageIcon(Lesson3.class.getClassLoader().getResource("highest.jpg")), 128, 255, 384);
pt.createTexture(32);[/java]
I am very positive that there is nothing wrong with file paths. Could someone help me.
Thank you in advance

If there is no reason why you use jme2 I strongly suggest to use jme3 since it is far more advanced in nearly every aspect.



The error happens because the Classpathstuff can’t find your specified file

1 Like

ya I know but that is the best my age old computer can handle :slight_smile:

Its a more of a java problem than JMonkey I guess. I removed those classloader stuff and gave file path directly and it worked.

I replaced this,

[java]new ImageIcon(Lesson3.class.getClassLoader().getResource("/home/user/NetBeansProjects/Hello3D/images/grassb.png"))[/java]

with

[java]new ImageIcon("path/to/file")[/java]



Now it works. hopefully I can do the same with all the other instances.

But I have no idea why this exception occur.



Thank you for the concern

Classpath loading is for when the ressources are in the classpath . (So put them in a src folder)

Have you tried β€œ/images/grassb.png” or similar?

1 Like

You can add resource locators:

[snippet id=β€œ11”]

1 Like

I placed image files in the package(mypkg) where Lesson3.java is and changed it as follows. it worked for me.

[java]Lesson3.class.getClassLoader().getResource("mypkg/grassb.png")[/java]