7 Replies Latest reply on Dec 4, 2008 7:45 AM by injpix

    Class returning null

    xtempore
      I was working on my code, busily making changes when suddenly I started to get the following error...

      "Cannot access a property or method of a null object reference"

      The weird thing is that this is occurring when calling a static function of a class. As far as Flex is concerned my class now has a value of null.

      The class is called "Global", and it contains a variety of static functions, static constants and static variables. It's been working fine for months but suddenly it has broken and I'm tearing my hair out trying to figure out why.

      I tried doing a trace to see what's going on ("Setting" us also a class)....

      trace(Setting);
      trace(Glb);

      ... returns ...

      [class Setting]
      null

      WTF? How can a class be null? I wondered it I had somehow messed up and had a line like Global=null, but I tried that and it wouldn't even compile.

      Anyone got any ideas?

      Could it me the internal load order of the packages? If so how do I change that to make sure Global loads first?

      Help!!!!!

      Please!
        • 1. Re: Class returning null
          John Hall Level 4
          Doesn't it drive you crazy when you feel like you're working backwards? I wonder if using the preinitialize event on the application to instantiate the class would help to ensure its existence upon applicationComplete. Though, if it's been working for months, gotta wonder if there's a conflict somewhere. I assume you did a Project > clean.
          • 2. Re: Class returning null
            Level 7

            "xtempore" <webforumsuser@macromedia.com> wrote in message
            news:gh5je1$e18$1@forums.macromedia.com...
            >I was working on my code, busily making changes when suddenly I started to
            >get
            > the following error...
            >
            > "Cannot access a property or method of a null object reference"
            >
            > The weird thing is that this is occurring when calling a static function
            > of a
            > class. As far as Flex is concerned my class now has a value of null.
            >
            > The class is called "Global", and it contains a variety of static
            > functions,
            > static constants and static variables. It's been working fine for months
            > but
            > suddenly it has broken and I'm tearing my hair out trying to figure out
            > why.
            >
            > I tried doing a trace to see what's going on ("Setting" us also a
            > class)....
            >
            > trace(Setting);
            > trace(Glb);
            >
            > ... returns ...
            >
            > [class Setting]
            > null
            >
            > WTF? How can a class be null? I wondered it I had somehow messed up and
            > had
            > a line like Global=null, but I tried that and it wouldn't even compile.
            >
            > Anyone got any ideas?
            >
            > Could it me the internal load order of the packages? If so how do I
            > change
            > that to make sure Global loads first?

            A lot of times static methods can't operate on instance variables and vice
            versa.


            • 3. Re: Class returning null
              levancho Level 3
              quote:

              Originally posted by: Newsgroup User

              "xtempore" <webforumsuser@macromedia.com> wrote in message
              news:gh5je1$e18$1@forums.macromedia.com...
              >I was working on my code, busily making changes when suddenly I started to
              >get
              > the following error...
              >
              > "Cannot access a property or method of a null object reference"
              >
              > The weird thing is that this is occurring when calling a static function
              > of a
              > class. As far as Flex is concerned my class now has a value of null.
              >
              > The class is called "Global", and it contains a variety of static
              > functions,
              > static constants and static variables. It's been working fine for months
              > but
              > suddenly it has broken and I'm tearing my hair out trying to figure out
              > why.
              >
              > I tried doing a trace to see what's going on ("Setting" us also a
              > class)....
              >
              > trace(Setting);
              > trace(Glb);
              >
              > ... returns ...
              >
              > [class Setting]
              > null
              >
              > WTF? How can a class be null? I wondered it I had somehow messed up and
              > had
              > a line like Global=null, but I tried that and it wouldn't even compile.
              >
              > Anyone got any ideas?
              >
              > Could it me the internal load order of the packages? If so how do I
              > change
              > that to make sure Global loads first?

              A lot of times static methods can't operate on instance variables and vice
              versa.




              IMHO, regardless of circumstances
              class reference should never bee null, that just sounds plain wrong,from any angle ,
              • 4. Re: Class returning null
                injpix Level 3
                quote:

                Could it me the internal load order of the packages?


                It could very well be. But I would suspect that it would return undefined instead of null. Just like if you were to access an RSL before it was loaded. At any rate, you can change the Build Order by navigating to:

                Windows> Preferences...> General> Workspace> Build Order
                • 5. Re: Class returning null
                  xtempore Level 1
                  After much cursing of Flex, I finally realised what my mistake was. Needless to say a more helpful error would have been nice.

                  Many of the static vars in Global are set in the initialization. One of them, which instantiated an object, caused a circular reference back to Global. This is what caused the problem.

                  It is still strange though that it did not generate a run-time error in the initialization code rather than later when I referenced the class.

                  Thanks to everyone who replied.
                  • 6. Re: Class returning null
                    levancho Level 3
                    myIP,
                    I have to disagree,with fact that it can be import order ...
                    IMHO, if in OOP, class reference existence is dependent on an import sequence that's pretty bad, also not sure how build order in flex is related to Class refference not being available,unlees there are more than one swf projects
                    ... its gotta be something else ,
                    • 7. Re: Class returning null
                      injpix Level 3
                      I never disagreed that it could of been the build order. If the OP was using SWCs in the form of RSLs (Runtime Shared Libraries) or SWFs (for bootstrapping a Flex app) then build order could very well have been a culprit, as you stated in your last post.