Skip to main content
Participant
October 31, 2010
Question

Getting 'null object ref' error on trying to add a label to a Box

  • October 31, 2010
  • 1 reply
  • 883 views

Hi,

I'm using Flash Builder 4 to create an action script based component. I've just started and the code right now is very simple - I have a class which extends the Box class. I set the width & height in the constructor and call an init() method where i create a label, add it using this.addChild(). When I run this I get the error

TypeError: Error #1009: Cannot access a property or method of a null object reference.

at mx.styles::StyleManager$/getStyleManager()

at mx.styles::StyleProtoChain$/getStyleManager()

at mx.styles::StyleProtoChain$/initProtoChain()

at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::initProtoChain()

at mx.core::UIComponent/regenerateStyleCache()

at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::addingChild()

at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::addingChild()

at mx.core::Container/addChildAt()

at mx.core::Container/addChild()

at component::Carousel/init()

at component::Carousel()

It errors out on line 125 of StyleManager.as

var styleManager:IStyleManager2 = IStyleManager2(moduleFactory.getImplementation("mx.styles::IStyleManager2"));

The code just preceding this line is

        if (!moduleFactory)

        {

            moduleFactory = SystemManagerGlobals.topLevelSystemManagers[0];

            // trace("no style manager specified, using top-level style manager");

        }

In the variables window I can see that modeluFactory is null.

Here's the code so far:

package component

{

     import flash.events.Event;

     import mx.containers.Box;

     import mx.controls.Label;


     public class Carousel extends Box

     {

          public function Carousel()

          {

               super();

               this.direction = "Horizontal";

               this.width = 100;

               this.height = 100;

               init();

          } // End of public function Carousel


          protected function init():void

          {

               var lb:Label = new Label();

               lb.text = "heloo";

               this.addChild(lb);

          }

     } // End of public class Carousel

} // End of package component

Any suggestions???

Thanks

Kunal

This topic has been closed for replies.

1 reply

Participant
January 11, 2011

I'm having exactly the same issue. This is happening to me when coding a very simple BarChart example. The code is available as part of a tutorial (http://livedocs.adobe.com/flex/3/html/charts_intro_7.html), the difference is that the tutorial uses it as part of an MXML file, while  I'm using it as part of an ActionScript file (.as).

In addition to this thread, I found this other discussion with same symptom: http://groups.google.com/group/reflex-platform/browse_thread/thread/de3e6c6608c82b8a#