- Home /
Help with NullReferenceException
I need another set of eyes to figure out a problem. I have an error of: NullReferenceException: Object reference not set to an instance of an object
The commented lines are where it happens:
private void DisplayMercAttributes(){
for(int cnt = 0; cnt < Enum.GetValues(typeof(MercenaryVariable)).Length; cnt++){
GUI.Label (new Rect(10, 70 + (cnt * LineHeight), 70, LineHeight), ((MercenaryVariable)cnt).ToString ());
//GUI.Label (new Rect(85, 70 + (cnt * LineHeight), 70, LineHeight), _protag.GetMercAttribute(cnt).AcceptedValue.ToString ());
}
private void DisplayPracAttributes(){
for(int cnt = 0; cnt < Enum.GetValues (typeof(PractitionerVariable)).Length; cnt++){
GUI.Label (new Rect(10, 70 + (cnt * LineHeight), 70, LineHeight), ((PractitionerVariable)cnt).ToString());
//GUI.Label (new Rect(85, 70 + (cnt * LineHeight), 70, LineHeight), _protag.GetPractAttribute(cnt).AcceptedValue.ToString());
}
The problem lies at _protag.GetMercAttribute(cnt) and _protag.GetPracAttribute(cnt). It shouldn't happen because the other attributes are set up the same way and work. The only difference between those attributes and these ones are that they only have 1 thing in their enum list, while the others have multiple things.
Read through my explanation of the null reference exception HERE. After having read it, show the relevant portion of your code and explain why you think the null reference should not happen. $$anonymous$$aybe someone will be able to help you then.
Answer by aldonaletto · Sep 15, 2013 at 07:47 PM
The only cause in this piece of code must be _protag not set or set to null. But there are other suspects that aren't showed: GetMercAttribute() and GetPracAttribute() apparently are functions that should return a reference to some class - they could also return null and cause the error. If this doesn't help solving your problem, post these two functions.