- Home /
This question was
closed Jul 30, 2015 at 12:29 AM by
rimawi for the following reason:
found some work around
Question by
rimawi · Aug 30, 2014 at 03:54 PM ·
uixmlnullreference
NullReferenceException: Object reference not set to an instance of an object
Hello, I am using the code below to read values from xml file.
the issue is : if i use:
question_TXT.text=reader.GetAttribute("Text");
nothing shows up in the text field.
if i use :
question_TXT.text=reader.GetAttribute("Text").ToString();
the value shows up in text field but i get NullReferenceException
Thanks
function fillInfo () {
var reader:XmlTextReader = new XmlTextReader(new StringReader(Malaf2.text));
// as long as there are info read.
while(reader.Read())
{
//if the element name= question assign it yo questionText
if(reader.Name == "Question")
{
// var questionText:Text=question_TXT.GetComponent("Text");
//var questionText:Text=GetComponent("UI.Text");
//question_TXT.text=reader.GetAttribute("Text");
question_TXT.text=reader.GetAttribute("Text").ToString();
}
}
}
Comment
it is part of the new UI.
import UnityEngine.UI; VAR question_TXT:Text;
Without further information, it appears that reader.GetAttribute("Text")
is returning null.
You can't call any method, including ToString() on a null reference. (Think of it like this, can you ask nobody their name?)