【发布时间】:2016-04-22 12:28:40
【问题描述】:
我已经尝试过这段代码,但它会生成 NullPointerException。
o.transform.parent =gameObject.transform;
与此相同:
o.transform.parent =gameObject.transform;
我也试过这个:
public Transform body;
//inside a function:
GameObject o = Instantiate(entry, new Vector3(addX*x+startX, addY*y+startY, 0), Quaternion.identity) as GameObject;
o.transform.parent = body;
我也试过上面的代码,但最后一行改成这样:
o.transform.parent = body.transform;
【问题讨论】:
-
哪个对象为空?
-
没说。这是错误消息:NullReferenceException: 对象引用未设置为对象 StudentListController.FillList (System.String strList) 的实例(在 Assets/Scripts/StudentListController.cs:44)StudentListController+
c__Iterator5.MoveNext ()(在资产/脚本/StudentListController.cs:23) -
第 44 行代码如下:o.transform.SetParent (body.transform);
-
我已经尝试过切换该行,就像我上面提到的代码一样。
-
实例化对象为空