我理解当(通常) myProg脚本的第54行中的一个内容不存在时,会产生以下错误消息:
NullReferenceException: Object reference not set to an instance of an object
myProg.OnGUI () (at Assets/Scripts/Editors/myProg.cs:54)但就我所能看到的和想象中的任何东西都不缺.
下面是代码片段的相关部分,第54行是.enabled (中间行)的位:
if( GUILayout.Button("SART07Johnson") )
{
stage.setFatigueInductor( new Sart07JohnsonDefinition(GetComponent<ExperimentCreator>().getExperiment().getAvailableTableName("SART07Johnson")) );
stage.setTypeOfFI( FatigueType.SART07Johnson );
SART07JohnsonEditor editorSart07Johnson = GetComponent<SART07JohnsonEditor>();
editorSart07Johnson.enabled = true;
editorSart07Johnson.Init( (Sart07JohnsonDefinition)stage.getFatigueInductor(), this.stage.StageName,GetComponent<ExperimentCreator>().getExperiment().GetExperimentName() );
GetComponent<NavigationTree>().CurrentEditor = editorSart07Johnson;
this.enabled = false;
}所以我想知道..。还有什么问题吗?我可以调查的其他特定原因是否会导致错误消息的产生?
发布于 2014-11-14 15:49:14
你是对的,它告诉你一个物体不存在。在本例中,editorSart07Johnson为null,您正在尝试从它获得一个属性(.enabled)。上面的行调用GetComponent,它根据文档“返回类型类型的组件(如果游戏对象附加了一个),如果没有返回null。”
因此,答案是您的游戏对象没有附加SART07JohnsonEditor类型的组件。
https://stackoverflow.com/questions/26933205
复制相似问题