setWrap() causes nullpointerexception?

I have a class for bump textures and I created a method to set all the texture’s their WrapMode at once but whenever I try to set the wrapmode of a texture I get a NullPointerException on the line where :setWrap() is called. What am I doing wrong?

Error:

[java]Caused by: java.lang.NullPointerException

at CantThinkOfName.BumpTexture.setWrapMode(BumpTexture.java:38)

at CantThinkOfName.BumpTexture.<init>(BumpTexture.java:22)

at Testing.PreMadeBumpTextures.<init>(PreMadeBumpTextures.java:15)

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

at java.lang.reflect.Constructor.newInstance(Constructor.java:513)[/java]

BumpTexture Class:

[java]public class BumpTexture{

private Texture DiffuseMap;

private Texture NormalMap;

private Texture GlowMap;

private Texture SpecularMap;

public _Texture(){

setWrapMode(WrapMode.Repeat);

}

public Texture getDiffuseMap(){return DiffuseMap;}

public void setDiffuseMap(Texture map){DiffuseMap = map;}

public Texture getNormalMap(){return NormalMap;}

public void setNormalMap(Texture map){NormalMap = map;}

public Texture getGlowMap(){return GlowMap;}

public void setGlowMap(Texture map){GlowMap = map;}

public Texture getSpecularMap(){return SpecularMap;}

public void setSpecularMap(Texture map){SpecularMap = map;}

private void setWrapMode(WrapMode mode){

this.DiffuseMap.setWrap(mode); // this line causes the nullpointer

this.NormalMap.setWrap(mode);

this.GlowMap.setWrap(mode);

this.SpecularMap.setWrap(mode);

}

}[/java]

That probably means DiffuseMap is null, How do you initialize it?

1 Like

Ugh, the switch from scripting to programming isn’t as easy as I’d hoped, I just keep making mistakes like this.



Well thank you very much :smiley:

Btw is there any documentary on texture wrapping? Im trying to tile my textures but I can’t find anything on the wiki regarding the subject.

mhh don’t know if there is for this particular matter, but usually, if you want to repeat your texture, let’s say 10 times, you have to set the wrap mode to wrap (like you did), and scale the texture coordinates by 0,1.

For this use mesh.scaleTextureCoordinates(new Vector2f(uScale,vScale));

1 Like