kotlin - NPE on constructor and superclass -



kotlin - NPE on constructor and superclass -

i have next code:

public class currentplayer(override val game: pewgame, spritesheet: string) : player(game, spritesheet)

the hierarchy follows: currentplayer -> class player -> trait movingentity -> trait entity.

the trait 'entity' has field 'val game: pewgame'. constructor player looks this:

public open class player(override val game: pewgame, spritesheet: string) : movingentity, inputadapter()

in constructor of player, if can phone call in kotlin, have this:

this.sprite = characterspritesheet(utilities.createtexturefromfile(spritesheet), this.game.getspritebatch(), 0.25f)

problem is, 'this.game' null, hence 'this.game.getspritebatch()' throws npe. can't explain in improve way, help appreciated. more precise, after using debugger:

i can see both game , this in player class. game not null, this.game null inexplicable reason.

thanks helping!

edit: forgot mention issue nowadays when instantiate currentplayer, , doesn't happen when instantiate player.

the problem store same info in 2 fields: override game in player , 1 time again in currentplayer, makes same info stored twice. incidentally, makes getter game property access uninitialized field in currentplayer instead of initialized 1 in player.

to prepare problem, remove override val currentplayer declaration:

public class currentplayer(game: pewgame, spritesheet: string) : player(game, spritesheet)

kotlin

Comments

Popular posts from this blog

javascript - THREE.js reposition vertices for RingGeometry -

javascript - I need to update the text of a paragraph by inline edit -

assembly - What is the addressing mode for ld, add, and rjmp instructions? -