c# - NullReferenceException was Unhandled (for a class) -
this question has answer here:
- what nullreferenceexception, , how fix it? 29 answers
i've been trying fix class null problem little bit. don't understand it. class null reason. make loadcontent null too. additional information says: object reference not set instance of object.
characterinfo chara;//chara class null chara.loadcontent(content);// error pointing //this behind chara.loadcontent(content); texture = content.load<texture2d>("art/blueanvil"); healthbar = content.load<texture2d>("art/healthbar");
started happening after add loadcontent constructor, class, , started using chara.loadcontent(content);
please me expand knowledge in c# can remember how fix this.
you need instantiate object:
characterinfo chara = new characterinfo();
at point, you're declaring variable, you're not assigning actual value it, hence exception.
if loadcontent
static factory method creates characterinfo
objects based on value of passed parameter, should be:
characterinfo chara = characterinfo.loadcontent(content);
Comments
Post a Comment