Null Pointer mat.setTexture()

Hello all, I seem to be having a problem setting my texture to a model. I downloaded a model for free and just drew up some lines and colors in paint and saved it as a .jpg. Trying to follow the tutorial but switch out the provided models with my own to ensure I understand the concept well.

I downloaded hte model for free from turbo squid : http://www.turbosquid.com/FullPreview/Index.cfm/ID/541072

My initial guess is that it has materials already attached to it and somehow hidden in the .obj file that it is looking for.





Below is the code (it is in the initialization function)

THe problem line is(according to eclipse) : wind_flatTexture.setTexture(“m_ColorMap”, assetManager.loadTexture(“textures/test_texture.jpg”));

I have also tried with an initial slash ("/textures/…")



[java]public void simpleInitApp() {



//creates a blue box at position 1,-1,1

Spatial space_craft = assetManager.loadModel("/models/warship_000.obj");

Material wind_flatTexture = new Material(assetManager, “Common/MatDefs/Misc/SimpleTextured.j3md”);



wind_flatTexture.setTexture(

“m_ColorMap”, assetManager.loadTexture("/textures/test_texture.jpg"));



space_craft.setMaterial(wind_flatTexture);



rootNode.attachChild(space_craft);





}[/java]



This is the trace that I get:

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.NullPointerException

at com.jme3.material.Material.setTexture(Material.java:320)

at hello.HelloJME3.simpleInitApp(HelloJME3.java:25)

at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:186)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:134)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:183)

at java.lang.Thread.run(Unknown Source)





Thanks for any tips,

~David

I also tried the following code to see what would happen and I am getting a problem:



[java] Box box = new Box(Vector3f.ZERO, 2.5f,2.5f,1.0f);

Spatial wall = new Geometry(“Box”, box );

Material mat_brick = new Material(

assetManager, “Common/MatDefs/Misc/SimpleTextured.j3md”);

mat_brick.setTexture(“m_ColorMap”,

assetManager.loadTexture(“textures/test_texture.jpg”));

wall.setMaterial(mat_brick);

wall.setLocalTranslation(2.0f,-2.5f,0.0f);

rootNode.attachChild(wall);[/java]



stack trace:

java.lang.NullPointerException

at com.jme3.material.Material.setTexture(Material.java:320)

at hello.HelloJME3.simpleInitApp(HelloJME3.java:34)

at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:186)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:134)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:183)

at java.lang.Thread.run(Unknown Source)



Same problem. Must not be the model. I thought a simple texture made in paint as a .jpg would work.

It’s “Textures” with an uppercase “T” and don’t use the slash at the beginning of the path

The texture is null because it can’t be found, it should say in the log above the exception that it failed to locate the asset.

Make sure that Textures/test_texture.jpg is actually on the classpath and that the letter cases are the same.

Cool, that solved my null pointer (adding to the class path).



I now seem to have an issue with loading the model now that I have switched to trying to use that. I get the stack trace:



java.io.IOException: Expected .mtl file! Got: ./Complete

at com.jme3.scene.plugins.OBJLoader.loadMtlLib(OBJLoader.java:287)

at com.jme3.scene.plugins.OBJLoader.readLine(OBJLoader.java:338)

at com.jme3.scene.plugins.OBJLoader.load(OBJLoader.java:516)

at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:224)

at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:346)

at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:356)

at hello.HelloJME3.simpleInitApp(HelloJME3.java:22)

at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:186)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:134)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:183)

at java.lang.Thread.run(Unknown Source)

Nov 10, 2010 2:06:37 PM com.jme3.asset.DesktopAssetManager loadAsset

WARNING: Error occured while loading resource models/skull.obj using OBJLoader

Nov 10, 2010 2:06:37 PM com.jme3.app.Application handleError

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]

java.lang.NullPointerException

at com.jme3.asset.ModelKey.createClonedInstance(ModelKey.java:54)

at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:250)

at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:346)

at com.jme3.asset.DesktopAssetManager.loadModel(DesktopAssetManager.java:356)

at hello.HelloJME3.simpleInitApp(HelloJME3.java:22)

at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:186)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:134)

at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:183)

at java.lang.Thread.run(Unknown Source)



Not sure whats up with the model, or why its looking for a .mtl file. There should be a link in the earlier in the topic.

Thanks,

~David

The MTL lib file specified in the OBJ file seems to be invalid.

Open the OBJ file in a text editor and find the “mtllib” statement, does it point to a .mtl file or something else?

mtllib ./Complete Skull 01 Flattened 131000.obj.mtl



This is the line that I have, the error seems to indicate: expected .mtl lib and got ./Complete



I tried throwing double quotes around the file path to see what happened, but to no avail. I have never played with these file formats, not really sure what it needs to point to or what to put there to get it to work properly.



Thanks for help/advice.

~David

This is definitely a bug in the importer. It doesn’t handle spaces correctly in the path. Also, I see there’s a ./ notation being used to go up a folder, I am not sure if it would work with the locators we are using.

I have committed a fix in SVN, please try and see if you still get the issue.

wow, so I have come across something totally different now…here is a complete stack trace, perhaps it will help you out. It would seem that there is an access violation.



I also would like to say that I have been trying to access the source code via svn, however my svn does not seem to beleive that the source at the location:

http://jmonkeyengine.googlecode.com/svn/trunk/ jmonkeyengine-read-only



I am using subclipse as my svn to try to bring this down. Is this infact the correct space to to download from?



Thanks for the help,

~David









Nov 15, 2010 2:26:56 PM com.jme3.system.JmeSystem initialize

INFO: Running on jMonkey Engine 3 Alpha 0.6

Nov 15, 2010 2:26:56 PM com.jme3.system.Natives extractNativeLibs

INFO: Extraction Directory #1: file:/C:/Users/David/Downloads/jME3/

Nov 15, 2010 2:26:56 PM com.jme3.system.Natives extractNativeLibs

INFO: Extraction Directory #2: C:UsersDavidresearch_workspaceHelloJME3

Nov 15, 2010 2:26:56 PM com.jme3.system.Natives extractNativeLibs

INFO: Extraction Directory #3: C:UsersDavidresearch_workspaceHelloJME3

Nov 15, 2010 2:26:56 PM com.jme3.system.lwjgl.LwjglAbstractDisplay run

INFO: Using LWJGL 2.5

Nov 15, 2010 2:26:56 PM com.jme3.system.lwjgl.LwjglDisplay createContext

INFO: Selected display mode: 640 x 480 x 0 @0Hz

Nov 15, 2010 2:26:56 PM com.jme3.system.lwjgl.LwjglAbstractDisplay initInThread

INFO: Display created.

Nov 15, 2010 2:26:57 PM com.jme3.system.lwjgl.LwjglAbstractDisplay initInThread

INFO: Adapter: igdumdx32

Nov 15, 2010 2:26:57 PM com.jme3.system.lwjgl.LwjglAbstractDisplay initInThread

INFO: Driver Version: 8.14.10.1930

Nov 15, 2010 2:26:57 PM com.jme3.system.lwjgl.LwjglAbstractDisplay initInThread

INFO: Vendor: Intel

Nov 15, 2010 2:26:57 PM com.jme3.system.lwjgl.LwjglAbstractDisplay initInThread

INFO: OpenGL Version: 2.0.0 - Build 8.14.10.1930

Nov 15, 2010 2:26:57 PM com.jme3.system.lwjgl.LwjglAbstractDisplay initInThread

INFO: Renderer: Intel 965/963 Graphics Media Accelerator

Nov 15, 2010 2:26:57 PM com.jme3.system.lwjgl.LwjglAbstractDisplay initInThread

INFO: GLSL Ver: 1.10 - Intel Build 8.14.10.1930

Nov 15, 2010 2:26:57 PM com.jme3.system.lwjgl.LwjglTimer

INFO: Timer resolution: 1000 ticks per second

Nov 15, 2010 2:26:57 PM com.jme3.renderer.lwjgl.LwjglRenderer initialize

INFO: Caps: [FrameBuffer, FrameBufferMRT, OpenGL20, ARBprogram, GLSL100, GLSL110, VertexTextureFetch]

Nov 15, 2010 2:26:57 PM com.jme3.asset.DesktopAssetManager

INFO: DesktopAssetManager created.

Nov 15, 2010 2:26:57 PM com.jme3.renderer.Camera

INFO: Camera created (W: 640, H: 480)

Nov 15, 2010 2:26:57 PM com.jme3.renderer.Camera

INFO: Camera created (W: 640, H: 480)

Nov 15, 2010 2:26:57 PM com.jme3.input.lwjgl.LwjglMouseInput initialize

INFO: Mouse created.

Nov 15, 2010 2:26:57 PM com.jme3.input.lwjgl.LwjglKeyInput initialize

INFO: Keyboard created.

Nov 15, 2010 2:26:57 PM com.jme3.audio.lwjgl.LwjglAudioRenderer initialize

INFO: Audio effect extension version: 1.0

Nov 15, 2010 2:26:57 PM com.jme3.audio.lwjgl.LwjglAudioRenderer initialize

INFO: Audio max auxilary sends: 2

Nov 15, 2010 2:26:57 PM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (Gui Node)

Nov 15, 2010 2:26:57 PM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (Statistics View)

Nov 15, 2010 2:26:57 PM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (Statistics View)

Nov 15, 2010 2:26:57 PM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (Statistics View)

Nov 15, 2010 2:26:57 PM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (Statistics View)

Nov 15, 2010 2:26:57 PM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (Statistics View)

Nov 15, 2010 2:26:57 PM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (Statistics View)

Nov 15, 2010 2:26:57 PM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (Statistics View)

Nov 15, 2010 2:26:57 PM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (Statistics View)

Nov 15, 2010 2:26:57 PM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (Statistics View)

Nov 15, 2010 2:26:57 PM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (Statistics View)

Nov 15, 2010 2:26:57 PM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (Statistics View)

Nov 15, 2010 2:26:57 PM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (Statistics View)

Nov 15, 2010 2:26:57 PM com.jme3.scene.Node attachChild

INFO: Child (BitmapFont) attached to this node (Statistics View)

Nov 15, 2010 2:26:57 PM com.jme3.scene.Node attachChild

INFO: Child (Statistics View) attached to this node (Gui Node)

Nov 15, 2010 2:26:57 PM com.jme3.asset.DesktopAssetManager loadAsset

WARNING: Cannot locate resource: models/Complete Skull 01 Flattened 131000.obj.mtl

Nov 15, 2010 2:26:57 PM com.jme3.scene.plugins.OBJLoader loadMtlLib

WARNING: Can’t find MTL file. Using default material for OBJ.

Nov 15, 2010 2:27:03 PM com.jme3.scene.Node attachChild

INFO: Child (Complete Skull 01 Flattened 131000-geom-0) attached to this node (Complete Skull 01 Flattened 131000-objnode)

Nov 15, 2010 2:27:03 PM com.jme3.scene.Node attachChild

INFO: Child (Complete Skull 01 Flattened 131000-geom-0) attached to this node (Root Node)

Nov 15, 2010 2:27:03 PM com.jme3.renderer.lwjgl.LwjglRenderer updateUniformLocation

WARNING: Uniform m_VertexColor is not declared in shader.

#

A fatal error has been detected by the Java Runtime Environment:

#

EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x19f290ef, pid=3032, tid=2044

#

JRE version: 6.0_21-b07

Java VM: Java HotSpot™ Client VM (17.0-b17 mixed mode windows-x86 )

Problematic frame:

C [ig4icd32.dll+0x1390ef]

#

An error report file with more information is saved as:

C:UsersDavidresearch_workspaceHelloJME3hs_err_pid3032.log

#

If you would like to submit a bug report, please visit:

http://java.sun.com/webapps/bugreport/crash.jsp

The crash happened outside the Java Virtual Machine in native code.

See problematic frame for where to report the bug.