3 Replies Latest reply on Jan 19, 2011 12:49 AM by pauland

    Cannot access null object reference in flex

    PoornimaBS

      Hi All,

       

      Please provide me the solution ASAP....for the below error........

       

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

       

          at Components::References/communicationServicesPort_resultHandler()[C:\Documents and Settings\xp\Adobe Flash Builder 4 Plug-in\LawPadPDA\src\Components\actionscript\ReferenceAS.as:345]

       

          at Components::References/__communicationServicesPort_result()[C:\Documents and Settings\xp\Adobe Flash Builder 4 Plug-in\LawPadPDA\src\Components\References.mxml:40]

       

          at flash.events::EventDispatcher/dispatchEventFunction()

       

          at flash.events::EventDispatcher/dispatchEvent()

       

          at com.adobe.fiber.services.wrapper::AbstractServiceWrapper/http://www.adobe.com/2008/flex/model/internal::propagateEvents()[C:\depot\DataServices\bra nches\lcds_modeler101\frameworks\projects\fiber-swc\src\com\adobe\fiber\services\wrapper\A bstractServiceWrapper.as:200]

       

          at flash.events::EventDispatcher/dispatchEventFunction()

       

          at flash.events::EventDispatcher/dispatchEvent()

       

          at mx.rpc::AbstractService/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\rpc\A bstractService.as:333]

       

          at mx.rpc.soap.mxml::WebService/dispatchEvent()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\ rpc\soap\mxml\WebService.as:267]

       

          at mx.rpc::AbstractOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E:\dev\4.0.0\frameworks\pro jects\rpc\src\mx\rpc\AbstractOperation.as:254]

       

          at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:\dev\4.0.0\frameworks\projec ts\rpc\src\mx\rpc\AbstractInvoker.as:318]

       

          at mx.rpc::Responder/result()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:5 6]

       

          at mx.rpc::AsyncRequest/acknowledge()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\rpc\AsyncR equest.as:84]

       

          at DirectHTTPMessageResponder/completeHandler()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\ messaging\channels\DirectHTTPChannel.as:446]

       

          at flash.events::EventDispatcher/dispatchEventFunction()

       

          at flash.events::EventDispatcher/dispatchEvent()

       

          at flash.net::URLLoader/onComplete()

       

       

       

       

      private function communicationServicesPort_resultHandler(event:ResultEvent):void{
                  str = new ArrayCollection();
                  if (event.token.result as ArrayCollection) { // When result contains more than one string
                      str = event.token.result as ArrayCollection;
                      if(str.length <= 15){ 
                          if(str.length<15)
                              nextLabel.enabled =false ; //  Here i am getting error for not accessing nextlabel i.e id of next button
                          else {
                              nextLabel.enabled =true ;
                          }
                          referenceDG.dataProvider = str; //Here i am getting error
                      }
                  }
                  else {// When result contains single string or validation message
                      str = new ArrayCollection([event.result]);
                      if(str[0] == "NULL"){
                          str[0]= "                              Sorry! No Search Results Found... Please do search again..........          ";
                          nextLabel.enabled = false;
                      }
                      referenceDG.dataProvider = str;
                  }
              }

        • 1. Re: Cannot access null object reference in flex
          pauland Level 4

          Learn to use the debugger and then you can inspect the variable values with the application stopped at the error.

           

          From your comments and the error, looks like referenceDG is null.

           

          You have another comment about another reference failing too ( nextLabel ), so maybe your result handler is being inoked beffore the application UI has completed loading. Difficullt to tell from bits of code.

          • 2. Re: Cannot access null object reference in flex
            PoornimaBS Level 1

            Hi,

            Thanks for ur reply,,

            I have posted u with some more code snippets .....please provide me solution ASAP

            .......................

             

            Reference.mxml

             

            <s:HGroup width="1003" height="45" gap="2">
                        <mx:Image id="judgements" width="98" minHeight="10" click="this.createMenu('judgements',JudgementsXMLTag)" buttonMode="true"
                                  maxHeight="350" maxWidth="250" height="41" source="assets/images/ReferencesImages/JudgementsImg.jpg" left="0"/>

               </s:HGroup>

             

             

            <mx:Canvas id="datagrid" width="100%" height="100%">
                            <mx:VBox width="100%" height="100%" paddingBottom="5" paddingLeft="1" paddingRight="0"
                                     paddingTop="10" verticalScrollPolicy="off" horizontalScrollPolicy="off">
                                <mx:DataGrid id="referenceDG" itemClick="openFile(event)"     //datagrid
                                             width="100%" height="100%" showHeaders="false"
                                             alternatingItemColors="[#ffffff,#ffffff]">
                                    <mx:columns>
                                        <mx:DataGridColumn dataField="*" fontWeight="normal" visible="false"
                                                           direction="ltr" fontGridFitType="pixel" color="#000000"
                                                           fontSize="12" fontStyle="normal" fontFamily="Verdana"
                                                           wordWrap="true" resizable="false" width="14"/>
                                        <mx:DataGridColumn dataField="*" fontWeight="normal" labelFunction="SplitFunc" 
                                                           direction="ltr" fontGridFitType="pixel" color="#000000"
                                                           fontSize="12" fontStyle="normal" fontFamily="Verdana"
                                                           wordWrap="true" resizable="false" width="14"/>
                                    </mx:columns>
                                </mx:DataGrid>
                                <mx:HRule width="968"/>
                                <mx:HBox horizontalAlign="right" width="968">
                                    <mx:LinkButton id="prevLabel" label="Prev" fontWeight="bold" enabled="{counter>1}" click="prv_clickHandler(event)" color="#FF8800"/>  //Previous button
                                    <mx:LinkButton id="nextLabel" label="Next" fontWeight="bold" click="nxt_clickHandler(event)" color="#FF8800"/>

            //Next Button
                                </mx:HBox>
                            </mx:VBox>
            </mx:Canvas>

             

             

             

            private function createMenu(btnName:String,xmlTag:XML):void {   //On click of judgements image
                        /*reader.htmlText="";*/
                        menu = new ScrollableArrowMenu();
                        menu = ScrollableArrowMenu.createMenu(null,xmlTag, false);
                        menu.labelField="@label";
                        menu.verticalScrollPolicy =  ScrollPolicy.OFF;
                        menu.arrowScrollPolicy =  ScrollPolicy.AUTO;
                        menu.maxHeight=350;
                        menu.maxWidth=250;
                        var pt:Point = new Point(0, 40);
                            menu.addEventListener(MenuEvent.ITEM_CLICK,JudgementsMenuBar_itemClickHandler); ///menu item click event listener
                            pt = judgements.localToGlobal(pt);
                        menu.show(pt.x, pt.y);
                    }

             

             

             

            protected function JudgementsMenuBar_itemClickHandler(event:MenuEvent):void /// On dropdown menu item click

             

                    {

             

                        //Alert.show("Data under process","No Data");

             

                        searchTxt.text ="";

             

                        searchFlag = false;

             

                        judgementItemLabel = null;

             

                        var judgementItemLabel:String = null;

             

                        judgementItemLabel = event.item.@label;

             

                        var judgementItemLabelSplit:String = null;

             

                        var judgementItemLabelSplitArray:Array = new Array();

             

                        judgementItemLabelSplitArray = judgementItemLabel.split(" ");

             

                        judgemntItemLabelAfterSplit=judgementItemLabelSplitArray[0];

             

                        judgementsTtlWndw = PopUpManager.createPopUp(this, JudgementMenubarClickPopup, true) as JudgementMenubarClickPopup;   /// opening a pop up.... once th user enters the I/P iam dispatching the event from popup

             

             

                        judgementsTtlWndw.addEventListener(ReferenceJudgementsEvent.SEARCH_CLICK_EVENT,searchButt onClickPopUp); //event listener for dispatched event from popup

             

             

                        judgementsTtlWndw.judgementMess.text = " Please Enter Furthur Keywords to be Searched with respect to " + event.item.@label;

             

                        judgementsTtlWndw.judgementitemlabelSplitPopUp.text = judgemntItemLabelAfterSplit+"btn";

             

                        PopUpManager.centerPopUp(judgementsTtlWndw);

             

                    }

             

             

             

             

            private function searchButtonClickPopUp( event:ReferenceJudgementsEvent ) : void

             

                    {

             

                        judgementFileDownloadString = event.judgementUserIp;

             

                        searchButtonClick();

             

                    }

             

            public function searchButtonClick():void {

                            RefTxtInput = StringUtils.stripTags(judgementFileDownloadString);

             

                            judgementFileDownloadString = null;

             

                            searchFlag = false;

             

                            counter = 1;

             

                            getSearchEngineForReferencePageResult.token = lawPadCommunicationServicesPort.getSearchEngineForReferencePage(RefTxtInput, 15, counter);

             

                    }

             

            /////////////LawPad Search//////////////////////////

             

                    private function lawPadCommunicationServicesPort_resultHandler(event:ResultEvent):void{

             

                        str = new ArrayCollection();

             

                        if (event.token.result as ArrayCollection) { // When result contains more than one string

             

                            str = event.token.result as ArrayCollection;

             

                            if(str.length <= 15){ 

             

                                if(str.length<15)

             

                                    nextLabel.enabled =false ;

             

                                else {

             

                                    nextLabel.enabled =true ; //error at this point

             

             

                                }

             

                                referenceDG.dataProvider = str; //error at this point

             

             

                            }

             

                        }

             

                    }

            • 3. Re: Cannot access null object reference in flex
              pauland Level 4

              "I have posted u with some more code snippets .....please provide me  solution ASAP"

               

              I am not here to provide a free debugging service "ASAP". Spend some time yourself in trying to understand what is happening rather than relying on others to just fix your code.