4 Replies Latest reply on Sep 20, 2012 7:29 AM by SamuelXiot

    null object reference while call other compenet function

    SamuelXiot Level 1

      I have create the following function in component A(which is productDetailComp)

       

      public  function  createProductDetailItem(productdetail:Productdetail):void{
                  productdetailService
      .createProductdetail(productdetail);
                  productdetailService
      .commit();
             
      }

       

       

      and in the component B, I call the function via

       

      var productdetail:Productdetail = new Productdetail();

      productDetailComp.createProductDetailItem(productdetail);

       

       

      but, why the following error pop up while invoking the createProductDetailItem() function? Need to create a instance for the function or the component productDetailComp??

       

       

      TypeError: Error #1009: Cannot access a property or method of a null object reference. at productDetailComp/onEdit()[C:\Users\School\Adobe Flash Builder 4.6\FYPadminSideV3\src\productDetailComp.mxml:80] at productDetailComp/__button2_click()[C:\Users\School\Adobe Flash Builder 4.6\FYPadminSideV3\src\productDetailComp.mxml:250]

        • 1. Re: null object reference while call other compenet function
          BBlommers Level 2

          I'm assuming you're calling this function via

          var productdetailComp:ProductdetailComp = new ProductdetailComp();

          productDetailComp.createProductDetailItem(productdetail);

           

           

          What does line 80 look like, of productDetailComp?

          Did you initialize the productDetailService-object?

          • 2. Re: null object reference while call other compenet function
            SamuelXiot Level 1

            if (isNew == true){//***********************************************

             

            one statment and nothing.

             

            the following code is

             

            if (isNew == true){//***********************************************

                                   

                                        pc.createProductDetailItem(productdetail);

                                        Alert.show("this is a new record");

                                        this.currentState == "Viewer"

                                           

                                    }else{//************************************************************

                                       

                                        pc.updateProductDetailItem(productdetail);

                                        Alert.show("this is an update");

                                        this.currentState == "Viewer"

                                           

                                           

                                    }

            • 3. Re: null object reference while call other compenet function
              SamuelXiot Level 1

              and the productDetailService is declared in the <fx:Ddeclarations>

               

               

              <productdetailservice:ProductdetailService id="productdetailService"

                                                                 fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)"

                                                                 showBusyCursor="true"/>

              • 4. Re: null object reference while call other compenet function
                SamuelXiot Level 1

                Soleved

                 

                by create a instance for the service and everything run perfectly