2 Replies Latest reply on Sep 10, 2012 5:39 AM by Sergey_Tokarev

    FYI: s:FormItem, Error #1009: Cannot access a property or method of a null object reference

    oroboros777

      In case anyone comes upon this extremely obscure problem, let my hours of sorrow guide you towards blessed relief.

       

      I was working with a very complicated Flex project that I have been working on since Flex Builder 3, still located in its original FB3 location, "C:\Documents and Settings\[myName]\My Documents\Flex Builder 3\[ProjectName].  When I installed Flash Builder 4.6, I imported this project using "File > Import Flash Builder Project ...", using 4.6.0 library path, 4.6.0 compiler, pretty much everything except the project folder itself was using the new linked resources, paths, etc.

       

      And all had been going well for a long time ... until today.

       

      For some reason when I added an s:FormItem to one of the components the following error would show up:

       

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

          at spark.utils::FTETextUtil$/getEmbeddedFontContext()[E:\dev\4.y\frameworks\projects\spark\s rc\spark\utils\FTETextUtil.as:207]

          at spark.utils::FTETextUtil$/calculateFontBaseline()[E:\dev\4.y\frameworks\projects\spark\sr c\spark\utils\FTETextUtil.as:136]

          at spark.components.supportClasses::GroupBase/get baselinePosition()[E:\dev\4.y\frameworks\projects\spark\src\spark\components\supportClass es\GroupBase.as:388]

          at spark.components::Group/get baselinePosition()[E:\dev\4.y\frameworks\projects\spark\src\spark\components\Group.as:284 ]

          at spark.layouts::ConstraintLayout/parseElementConstraints()[E:\dev\4.y\frameworks\projects\ spark\src\spark\layouts\ConstraintLayout.as:1818]

          at spark.layouts::ConstraintLayout/parseConstraints()[E:\dev\4.y\frameworks\projects\spark\s rc\spark\layouts\ConstraintLayout.as:1632]

          at spark.layouts::ConstraintLayout/measure()[E:\dev\4.y\frameworks\projects\spark\src\spark\ layouts\ConstraintLayout.as:414]

          at spark.components.supportClasses::GroupBase/measure()[E:\dev\4.y\frameworks\projects\spark \src\spark\components\supportClasses\GroupBase.as:1148]

          at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::measureSizes()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:8506]

          at mx.core::UIComponent/validateSize()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\ UIComponent.as:8430]

          at spark.components::Group/validateSize()[E:\dev\4.y\frameworks\projects\spark\src\spark\com ponents\Group.as:1012]

          at mx.managers::LayoutManager/validateSize()[E:\dev\4.y\frameworks\projects\framework\src\mx \managers\LayoutManager.as:665]

          at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.y\frameworks\projects\framewo rk\src\mx\managers\LayoutManager.as:792]

          at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.y\frameworks\projects \framework\src\mx\managers\LayoutManager.as:1180]

       

      pointing me to line 207 of FTETextUtil.as:

       

      206.     fontContext = embeddedFontRegistry.getAssociatedModuleFactory(

      207.           font, bold, italic, client, moduleFactory, localLookup, true);

       

      Rather odd error for adding a simple tag.  I figured there was some sort of conflict somewhere in the component stack.  So I go through each component, one by one, hour upon hour of testing, eliminating block after block of code, component after component, class after class, scripts, stylesheets, namespace declarations, damned near everything ... until I finally get to this:

       

      <?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" minWidth="955" minHeight="600">

       

              <s:FormItem />

         

      </s:Application>

       

      And it's still erroring the exact same way.  (Yes, I tried it in a Form, too, no difference.)  Now obviously something is quite wrong at this stage.  When all you have is the application and one simple tag with no properties and it's still erroring, something is seriously fubar.

       

      So I test s:FormItem in new projects, created outside of the FB3 location.  Everything works.  (One would hope!)  Then I created a new Application, cut-and-pasted all of my old App code into the new Application, copied over all of the files into duplicate files in the new folder location - everything works fine.  I have looked at all the properties of the two projects (build path, compilers, etc) and I can't spot a single difference other than the project folder location, "Properties > Resources > Linked Resources > Path Variables > PROJECT_LOC" ... and yet ...

       

      Bottom line, in case anyone has this obscure issue, and finds this post, this is your answer.  For some reason imported older projects trigger this error with FormItem and its null object problems with getAssociatedModuleFactory.  Start a new project, move your components, class files, etc, into the new folder, and all will work once again as it should.

       

      What a colossally weird and time-consuming PITA.