java - TiledMapTile set texture region gives NullPointerException -
i'm having trouble setting texture region tiledmaptile. gives me nullpointerexception
, have no idea why.
here code:
tiledmaptile cointile; public void show () { maptexture1 = new texture(gdx.files.internal("maps/other/texture1.png")); textureregion maptexture1region = new textureregion(maptexture1, 32, 0, 16, 16); cointile.settextureregion(maptexture1region); }
and here error:
04-09 21:57:18.222: e/androidruntime(7792): java.lang.nullpointerexception
04-09 21:57:18.222: e/androidruntime(7792): @ com.never.mind.screens.gamescreen.show(gamescreen.java:225)
which leads line:
cointile.settextureregion(maptexture1region);
usually, nullpointerexception happens when did not initialize in code.
since did not provide full code, give suggestions. did
maptexture1 = new texture(gdx.files.internal("maps/other/texture1.png"));
you should also
cointile = new tiledmaptile () { @override public int getid() { return 0; } @override public void setid(int id) { } @override public blendmode getblendmode() { return null; } @override public void setblendmode(blendmode blendmode) { } @override public textureregion gettextureregion() { return null; } @override public void settextureregion(textureregion textureregion) { } @override public float getoffsetx() { return 0; } @override public void setoffsetx(float offsetx) { } @override public float getoffsety() { return 0; } @override public void setoffsety(float offsety) { } @override public mapproperties getproperties() { return null; } }
by way read api spcific paremeters.
since new java read here grasp of nullpointers