I have this initialization of a prefab:
GameObject e = Instantiate(entry, new Vector3(x, y, 0), Quaternion.identity) as GameObject;
I know that it is successfully instantiated because I can see a clone on my hierarchy. However, if I try to access it, there is a NullReferenceException. I tried this:
Debug.Log(e.ToString());
And this:
e.transform.SetParent (GameObject.Find("Canvas").transform);
But it shows this error
NullReferenceException: Object reference not set to an instance of an object StudentListController.FillList (System.String strList) (at Assets/Scripts/StudentListController.cs:45) StudentListController+c__Iterator5.MoveNext () (at Assets/Scripts/StudentListController.cs:23)
This is the code of FillList:
void FillList(string strList) {
    string[] studentData;
    string[] studentList = strList.Split (';');
    int startX = -253;
    int startY = 70;
    int addX = 100;
    int addY = 30;
    for (int y = 0; y<studentList.Length; y++ ) {
        string student = studentList[y];
        studentData = student.Split(',');
        for(int x = 0; x<studentData.Length; x++) {
            string data = studentData[x];
            if (x==3) {
                data = getAgeFromBirthdate(data).ToString();
            } else if (x==4) {
                data = getSex(data).ToString();
            } 
            GameObject e = Instantiate(entry, new Vector3(startX + 100*x, startY + 40*y, 0), Quaternion.identity) as GameObject;
            //e.GetComponent<Text> ().text = data;
            //e.transform.SetParent (GameObject.Find("Canvas").transform);
        }
    }
}
 
     
    