# Null refrence error when attepting to addChild

**URL:** https://forum.kirupa.com/t/null-refrence-error-when-attepting-to-addchild/304762
**Category:** flash
**Created:** [February 13, 2010, 5:17am UTC](https://forum.kirupa.com/t/null-refrence-error-when-attepting-to-addchild/304762 "2010-02-13T05:17:59Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![soon2bdead](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@soon2bdead](https://forum.kirupa.com/u/soon2bdead)
#### Post date: [February 13, 2010, 5:17am UTC](https://forum.kirupa.com/t/null-refrence-error-when-attepting-to-addchild/304762/1 "2010-02-13T05:17:59Z")

</div>

I am attempting to make a class that handles the building in a game, but I can’t get the object to come on stage. I can get everything to work if I am on the timeline, just not from this class.

I’ve been getting this:

TypeError: Error #1009: Cannot access a property or method of a null object reference.  
at build$/newBuild()[/Users/student/Desktop/attack/build.as:19]

I attempted to see if my **building** variable was null so i did a trace…

trace (building);  
and got:  
[object base]

```auto

package {

 import flash.display.Sprite;
 import flash.display.Stage;
 import base; 
 
 public class build {
    
    public static var theStage:Stage;
    
     public static function newBuild():void
      {
        
        var building:base = new base();
        trace(building);
        building.x = 250;
        building.y = 250;
        theStage.addChild(building);

      }
   }
}

```

This class is being called from the timeline with:

build.newBuild();

Thanks for any help! =]
