# NullReferenceException (122315)

**URL:** https://discussions.unity.com/t/nullreferenceexception-122315/122315
**Category:** Questions & Answers
**Created:** [November 14, 2014, 6:23pm UTC](https://discussions.unity.com/t/nullreferenceexception-122315/122315 "2014-11-14T18:23:37Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![drhmiri](https://avatars.discourse-cdn.com/v4/letter/d/7ba0ec/32.png) [@drhmiri](https://discussions.unity.com/u/drhmiri)
#### Post date: [November 14, 2014, 6:23pm UTC](https://discussions.unity.com/t/nullreferenceexception-122315/122315/1 "2014-11-14T18:23:37Z")

</div>

I understand the following error message is caused when (in general) Unity is telling me that one of the things in line 54 of the myProg script doesn’t exist:

```
NullReferenceException: Object reference not set to an instance of an object
myProg.OnGUI () (at Assets/Scripts/Editors/myProg.cs:54)

```

But as far as I can see and figure, there is nothing missing there in any way…

Here is the relevant part of the code snippet, and line 54 is the bit with `.enabled` (middle line):

```
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;
	}

```

So, I am wondering… what else could be the problem? Any specific other reason that I could look into, that might be causing this error message to be generated?

EDIT: `GetComponent` calls `SART07JohnsonEditor` which means my game object now has `SART07JohnsonEditor` attached? Is that not right?

---

<div class="post-metadata">

### Author: ![static\_cast](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@static\_cast](https://discussions.unity.com/u/static_cast)
#### Post date: [November 14, 2014, 6:47pm UTC](https://discussions.unity.com/t/nullreferenceexception-122315/122315/2 "2014-11-14T18:47:45Z")

</div>

EDIT: Well, I figured out that you meant to say AddComponent.

> **[Unity - Scripting API: GameObject.AddComponent](https://docs.unity3d.com/ScriptReference/GameObject.AddComponent.html)**
