13 Replies Latest reply on Jun 6, 2011 11:04 AM by Brian Vaughn

    null-pointer errors with Labels caused by LayoutManager validateSize()

    Brian Vaughn

      This morning I've been trying to load a relatively simple Application into a SWFLoader for display within another application. I keep getting null-pointer errors in Labels though (stack traces below). It seems like the LayoutManager is trying to measure these labels before they've been fully initialized and they're errorring. (It is probably worth pointing out that this application runs without error when launched directly.)

       

      The Labels that are erroring are very simple, example:

      <mx:Label width="100%" fontSize="18" textAlign="center" text="{ bindableValue }" />
      
      

       

      With the MX Label, I run into the following error:

      TypeError: Error #2007: Parameter antiAliasType must be non-null.
           at flash.text::TextField/set antiAliasType()
           at mx.core::UITextFormat/measure()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UITextFormat.as:570]
           at mx.core::UITextFormat/measureText()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UITextFormat.as:492]
           at mx.core::UIComponent/measureText()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:8605]
           at mx.controls::Label/measureTextFieldBounds()[E:\dev\4.x\frameworks\projects\framework\src\mx\controls\Label.as:1616]
           at mx.controls::Label/measure()[E:\dev\4.x\frameworks\projects\framework\src\mx\controls\Label.as:1404]
           at mx.core::UIComponent/measureSizes()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:8216]
           at mx.core::UIComponent/validateSize()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:8140]
           at mx.managers::LayoutManager/validateSize()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:617]
           at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:709]
           at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1072]
      

       

      First thing I tried was swapping out for a Spark label...

      <s:Label width="100%" fontSize="18" textAlign="center" text="{ bindableValue }" />
      

       

      With the Spark Label, I get the following error:

      TypeError: Error #2007: Parameter justificationStyle must be non-null.
           at flash.text.engine::EastAsianJustifier/set justificationStyle()
           at spark.components::Label/createTextLines()[E:\dev\4.x\frameworks\projects\spark\src\spark\components\Label.as:802]
           at spark.components::Label/http://www.adobe.com/2006/flex/mx/internal::composeTextLines()[E:\dev\4.x\frameworks\projects\spark\src\spark\components\Label.as:474]
           at spark.components.supportClasses::TextBase/measure()[E:\dev\4.x\frameworks\projects\spark\src\spark\components\supportClasses\TextBase.as:533]
           at mx.core::UIComponent/measureSizes()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:8216]
           at mx.core::UIComponent/validateSize()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:8140]
           at mx.managers::LayoutManager/validateSize()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:617]
           at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:709]
           at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.x\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1072]
      

       

      I've spent some time Googling this issue but still haven't found a solution. One thing I did try (based on a forum post I came across) was listening for the creation of the Labels and calling "regenerateStyleCache" on them but that did not seem to have any impact.

       

      Thanks in advance if anyone is able to help point me in the right direction here!

        • 1. Re: null-pointer errors with Labels caused by LayoutManager validateSize()
          Flex harUI Adobe Employee

          Someone's autoresponder is responding to all forum posts.

           

          Is the SWFLoader on the display list?  Could there be a collision between

          the name of the sub-app and some other component in the main app?

          • 2. Re: null-pointer errors with Labels caused by LayoutManager validateSize()
            Brian Vaughn Level 1

            Yeah, that auto-responder marking all posts as "possibly answered" is a pretty big short-coming of the forum system.

             

            Right, so regarding what you said- no, that shouldn't be the case. Both my main loader application and the SWF it's loading exist in the same Flex project. One is just a test-harness to let me load and display the other one. (I'm developing a module to be loaded into another application but I want to be able to test and debug it locally.)

             

            If I launch the module directly, no errors. If I load it through a SWFLoader, I get errors.

             

            As for the SWFLoader being on the display list, yes. I've tried a variety of things, including:

            • Declaring the SWFLoader in MXML
            • Creating the SWFLoader in ActionScript and adding it to the display list manually
            • Creating the SWFLoader, listening for Event.INIT, then adding its "content" object to the display list
            • Creating the SWFLoader, listening for Event.INIT, then listening to its "content" object for FlexEvent.APPLICATION_COMPLETE and adding the content object's "application" object to the display list

             

            Neither of those approaches changed the error in any way so I stopped looking into that angle.

             

            I have also looked into hooking into the initialization sequence and manually assigning a non-null value to "antiAliasType" myself:

            label.determineTextFormatFromStyles().antiAliasType = "normal";
            

             

            Unfortunately, the "cachedTextFormat" value this call operates on is nulled out by UIComponent's "notifyStyleChangeInChildren" method (triggered by LayoutManager when it calls "validateProperties").

             

             

            • 3. Re: null-pointer errors with Labels caused by LayoutManager validateSize()
              Brian Vaughn Level 1

              Continuing efforts to narrow this down have resulted in diffenrent runtime errors. For instance, I tried to simplify my Label to see if I could get around the initial layout. Instead of center-aligning text I went with:

               

              <mx:Label width="100%" text="{ bindableValue }" />
              
              

               

              Re-running my application I now see a different null-pointer error:

               

              TypeError: Error #1009: Cannot access a property or method of a null object reference.
                   at mx.core::UIComponent/getStyle()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:10632]
                   at mx.core::UIComponent/getTextFieldClassName()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:12167]
                   at mx.core::UIComponent/createInFontContext()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:12132]
                   at mx.controls::Label/http://www.adobe.com/2006/flex/mx/internal::createTextField()[E:\dev\4.x\frameworks\projects\framework\src\mx\controls\Label.as:1505]
                   at mx.controls::Label/createChildren()[E:\dev\4.x\frameworks\projects\framework\src\mx\controls\Label.as:1318]
                   at mx.core::UIComponent/initialize()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:7349]
                   at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:7241]
                   at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:3972]
                   at mx.core::Container/addChildAt()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:2616]
                   at mx.core::Container/addChild()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:2534]
                   at mx.core::Container/createComponentFromDescriptor()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:4392]
                   at mx.core::Container/createComponentsFromDescriptors()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:4181]
                   at mx.core::Container/createChildren()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:3187]
                   at mx.core::UIComponent/initialize()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:7349]
                   at mx.core::Container/initialize()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:3129]
                   at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:7241]
                   at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:3972]
                   at mx.core::Container/addChildAt()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:2616]
                   at mx.core::Container/addChild()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:2534]
                   at mx.core::Container/createComponentFromDescriptor()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:4392]
                   at mx.core::Container/createComponentsFromDescriptors()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:4181]
                   at mx.core::Container/createChildren()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:3187]
                   at mx.core::UIComponent/initialize()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:7349]
                   at mx.core::Container/initialize()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:3129]
                   at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:7241]
                   at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:3972]
                   at mx.core::Container/addChildAt()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:2616]
                   at mx.core::Container/addChild()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:2534]
                   at mx.core::Container/createComponentFromDescriptor()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:4392]
                   at mx.core::Container/createComponentsFromDescriptors()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:4181]
                   at mx.core::Container/createChildren()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:3187]
                   at mx.core::UIComponent/initialize()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:7349]
                   at mx.core::Container/initialize()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:3129]
                   at views::Header/initialize()
                   at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:7241]
                   at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:3972]
                   at mx.core::Container/addChildAt()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:2616]
                   at mx.core::Container/addChild()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:2534]
                   at mx.core::Container/createComponentFromDescriptor()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:4392]
                   at mx.core::Container/createComponentsFromDescriptors()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:4181]
                   at mx.core::Container/createChildren()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:3187]
                   at mx.core::UIComponent/initialize()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:7349]
                   at mx.core::Container/initialize()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:3129]
                   at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:7241]
                   at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:3972]
                   at mx.core::Container/addChildAt()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:2616]
                   at mx.core::Container/addChild()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:2534]
                   at mx.core::Container/createComponentFromDescriptor()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:4392]
                   at mx.core::Container/createComponentsFromDescriptors()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:4181]
                   at mx.core::Container/createChildren()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:3187]
                   at mx.core::UIComponent/initialize()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:7349]
                   at mx.core::Container/initialize()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:3129]
                   at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:7241]
                   at mx.core::Container/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:3972]
                   at mx.core::Container/addChildAt()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:2616]
                   at mx.core::Container/addChild()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:2534]
                   at mx.core::Container/createComponentFromDescriptor()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:4392]
                   at mx.core::Container/createComponentsFromDescriptors()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:4181]
                   at mx.core::Container/createChildren()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:3187]
                   at mx.core::UIComponent/initialize()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:7349]
                   at mx.core::Container/initialize()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\Container.as:3129]
                   at views::MjobVisualizerUI/initialize()
                   at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::childAdded()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:7241]
                   at mx.core::UIComponent/addChildAt()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:6947]
              
              

               

              The UIComponent at the top of that Stack is still my Label. The "_nonInheritingStyles" attribute that "getStyle" is attempting to access is null.

               

              • 4. Re: null-pointer errors with Labels caused by LayoutManager validateSize()
                Brian Vaughn Level 1

                I also just tried bumping my Flex SDK version to 4.5 to see if the issue had been fixed. No luck.

                • 5. Re: null-pointer errors with Labels caused by LayoutManager validateSize()
                  Flex harUI Adobe Employee

                  If you plan to use a module, then create a module and a test harness that

                  uses ModuleLoader instead of a sub-app and SWFLoader.  Then see what errors

                  show up.  Fundamentally, the styles are not being made available to the

                  sub-app.

                  • 6. Re: null-pointer errors with Labels caused by LayoutManager validateSize()
                    Brian Vaughn Level 1

                    I'm sorry if I'm misunderstanding your reply, but why shouldn't I be able to load 1 SWF (an Application) into another SWF (also an Application) using SWFLoader? My choice of wording ("module") was probably unfortunate given that there is actually a Module class.

                    • 7. Re: null-pointer errors with Labels caused by LayoutManager validateSize()
                      Brian Vaughn Level 1

                      Here is a really simple re-creation of my problem. Using either Flex 4.1 or 4.5, create a project and define the following 2 Application files:

                       

                      Main.mxml

                      <?xml version="1.0" encoding="utf-8"?>
                      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                                     xmlns:s="library://ns.adobe.com/flex/spark" 
                                     xmlns:mx="library://ns.adobe.com/flex/mx"
                                     xmlns:local="*">
                           <mx:Label width="100%" textAlign="center" text="Main.mxml" />
                      </s:Application>
                      

                       

                      TestHarness.mxml

                      <?xml version="1.0" encoding="utf-8"?>
                      <s:Application initialize="init()"
                                     xmlns:fx="http://ns.adobe.com/mxml/2009" 
                                     xmlns:s="library://ns.adobe.com/flex/spark" 
                                     xmlns:mx="library://ns.adobe.com/flex/mx">
                           
                           <fx:Script>
                                <![CDATA[
                                     import mx.controls.SWFLoader;
                                     import mx.events.FlexEvent;
                                     import mx.managers.SystemManager;
                                     
                                     private var swfLoader:SWFLoader;
                                     
                                     private function init():void {
                                     swfLoader = new SWFLoader();
                                     swfLoader.addEventListener(
                                          Event.INIT,
                                          function( event:Event ):void {
                                               swfLoader.content.addEventListener(
                                                    FlexEvent.APPLICATION_COMPLETE,
                                                    function( event:Event ):void {
                                                         addElement( ( swfLoader.content as SystemManager ).application as Main );
                                                    } );
                                          } );
                                     swfLoader.load( "Main.swf" );
                      
                                     }
                                ]]>
                           </fx:Script>
                      </s:Application>
                      

                       

                      Interestingly enough, in my test project, there are a couple of ways to prevent this RTE from happening (but neither works in the context of my larger application):

                      • Declare the SWFLoader in MXML
                      • Add the SWFLoader element to the stage directly (instead of adding the loaded app).
                      • 8. Re: null-pointer errors with Labels caused by LayoutManager validateSize()
                        Flex harUI Adobe Employee

                        In this case, the SWFLoader is not on the display list until after the load

                        which is not supported.

                        • 9. Re: null-pointer errors with Labels caused by LayoutManager validateSize()
                          Brian Vaughn Level 1

                          Would you mind pointing out where (in the docs) it says that you can't call SWFLoader#load if the SWFLoader is not already on the display list? I don't see any mention of it in the reference docs: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/SWFLoader.h tml

                           

                          Anyway, that's a bit beside the point. This was just an example that reproduced the same RTE that I'm seeing in my larger (and harder-to-post) project. As I said, despite using an MXML-defined SWFLoader in my larger project I still receive the null-pointer errors triggered by LayoutManager.

                          • 10. Re: null-pointer errors with Labels caused by LayoutManager validateSize()
                            Flex harUI Adobe Employee

                            We should probably add that to the docs.  You're not the first person to hit

                            this issue.

                             

                            If you parent your SWFLoader in the example, doesn't the problem go away?

                             

                            In your more complex project, try setting a breakpoint on a Event.COMPLETE

                            handler and seeing if the SWFLoader is parented or not.

                             

                            Also make sure there are no warnings from the compiler in Flex 4.5.  We

                            added some warning that will catch some things that can muck up styles.

                            • 11. Re: null-pointer errors with Labels caused by LayoutManager validateSize()
                              Brian Vaughn Level 1

                              I am surprised that a known error condition is not already in the Docs. Yeah, it would be nice if someone could add it.

                               

                              Flex harUI wrote:

                               

                              Also make sure there are no warnings from the compiler in Flex 4.5.  We

                              added some warning that will catch some things that can muck up styles.

                               

                              I am also surprised to discover that this was the culprit. Resolving the following (seemingly innocuous) warning has made the problem go away: "<MyApplicationName> is a module or application that is directly referenced. This will cause <MyApplicationName> and all of its dependencies to be linked in with <MyTestHarnessName>. Using an interface is the recommended practice to avoid this."

                               

                              Seems like that warning message should be worded a bit more strongly.

                               

                              Anyway, thanks for your help. I appreciate it.

                              • 12. Re: null-pointer errors with Labels caused by LayoutManager validateSize()
                                Flex harUI Adobe Employee

                                You can reference past discussion on the issue of referencing other modules

                                and apps from the main app.  Doing so actually links in the class and all

                                its dependencies, defeating the separation.  If you look at the main SWF, it

                                should now be smaller.

                                • 13. Re: null-pointer errors with Labels caused by LayoutManager validateSize()
                                  Brian Vaughn Level 1

                                  I get that this leads to smaller SWF size and that's a good thing typically. However, in this case, since I was only running the test harness locally to make debugging easier- I was surprised to find that such a serious error was hiding behind such a seemingly harmless, optimization warning.

                                   

                                  In either case, at least I know now.