首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NullReferenceException @ OnGUI

NullReferenceException @ OnGUI
EN

Stack Overflow用户
提问于 2014-11-14 15:20:17
回答 1查看 211关注 0票数 0

我理解当(通常) myProg脚本的第54行中的一个内容不存在时,会产生以下错误消息:

代码语言:javascript
复制
NullReferenceException: Object reference not set to an instance of an object
myProg.OnGUI () (at Assets/Scripts/Editors/myProg.cs:54)

但就我所能看到的和想象中的任何东西都不缺.

下面是代码片段的相关部分,第54行是.enabled (中间行)的位:

代码语言:javascript
复制
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;
    }

所以我想知道..。还有什么问题吗?我可以调查的其他特定原因是否会导致错误消息的产生?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-14 15:49:14

你是对的,它告诉你一个物体不存在。在本例中,editorSart07Johnson为null,您正在尝试从它获得一个属性(.enabled)。上面的行调用GetComponent,它根据文档“返回类型类型的组件(如果游戏对象附加了一个),如果没有返回null。”

因此,答案是您的游戏对象没有附加SART07JohnsonEditor类型的组件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26933205

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档