9 Replies Latest reply on Dec 7, 2009 4:00 PM by cyber0897

    cannot access a property or method of a null object reference

    cyber0897 Level 1

      hey guys... just like the title suggests...

      i get that error on the trouble.dataProvider = resultData.menu.apx32.troubleShooting.item; line

       

      and as you can see the line right above it has the exact same code... and that seems to work just fine...

       

      any help is appretiated!!!

       

      this is the code i have

       

       

      mxml file:

                  <mx:VBox label="USER OPTIONS" width="100%" height="100%">
                      <s:List id="userOptions" width="100%" height="100%" itemRenderer="modules.apx32.myComponents.listRenderer"
                              borderAlpha="0">
                      </s:List>
                  </mx:VBox>
                  <mx:VBox label="TROUBLESHOOTING">
                      <s:List id="trouble" width="100%" height="100%" itemRenderer="modules.apx32.myComponents.listRenderer"
                              borderAlpha="0">
                      </s:List>
                  </mx:VBox>

       

      actionscript file:

       

          private function myXml_resultHandeler(event:ResultEvent):void{
              var resultData:Object = event.result;
             
              userOptions.dataProvider = resultData.menu.apx32.userOptions.item;
              trouble.dataProvider = resultData.menu.apx32.troubleShooting.item;

       

          }

        • 2. Re: cannot access a property or method of a null object reference
          mewk Level 3

          and as you can see the line right above it has the exact same code...

          uhm. are you sure??

           

          the dataProvider for userOptions is resultData.menu.apx32.userOptions.item

          and for trouble it's resultData.menu.apx32.troubleShooting.item

           

          - e

          • 3. Re: cannot access a property or method of a null object reference
            cyber0897 Level 1

            what i ment to say was its relatively similar... the code i have in there should be getting two different values... but using the exact same method...

             

            my xml contains both of the tags... and when i hit the debug button, it it shows me that the array contains both troubleshooting, and userOptions...

             

            the xml is as follows

             

            <?xml version="1.0" encoding="UTF-8" standalone="no" ?>

             

            <menu>
               <apx32>
                      <userOptions>
                        <item label="Adjust Volume">
                               <images>
                                  <url>images/APX32-adjustingVolume_01.png</url>
                               </images>
                               <video>true</video>
                        </item>
                        <item label="Arm/Disarm System">
                            <images>
                                <img url="images/APX32-armDisarm_01.png"/>
                                <img url="images/APX32-armDisarm_02.png"/>
                                <img url="images/APX32-armDisarm_03.png"/>
                                <img url="images/APX32-armDisarm_04.png"/>
                            </images>
                               <video>
                                   <videoPresent>true</videoPresent>
                                   <url></url>
                               </video>
                        </item>
                        <item label="Change Mastercode">
                            <images>
                                <img url="images/APX32-changeMasterCode_01.png"/>
                                <img url="images/APX32-changeMasterCode_02.png"/>
                            </images>
                            <video>
                                <videoPresent>true</videoPresent>
                                   <url></url>
                               </video>
                        </item>
                        <item label="Secondary Codes">
                            <images>
                                <img url="images/APX32-secondaryCode_01.png"/>
                                <img url="images/APX32-secondaryCode_02.png"/>
                                <img url="images/APX32-secondaryCode_03.png"/>
                            </images>
                            <video>
                                <videoPresent>false</videoPresent>
                                   <url></url>
                               </video>
                        </item>
                        <item label="Bypass the Sensors">
                            <images>
                                <img url="images/APX32-bypassZone_01.png"/>
                                <img url="images/APX32-bypassZone_02.png"/>
                            </images>
                            <video>
                                <videoPresent>false</videoPresent>
                                   <url></url>
                               </video>
                        </item>
                        <item label="Record/Delete Messages">
                            <images>
                                <img url="images/APX32-recordDeleteMessage_01.png"/>
                                <img url="images/APX32-recordDeleteMessage_02.png"/>
                            </images>
                            <video>
                                <videoPresent>false</videoPresent>
                                   <url></url>
                               </video>
                        </item>
                        <item label="Set Time">
                            <images>
                                <img url="images/APX32-settingTime_01.png"/>
                            </images>
                            <video>
                                <videoPresent>true</videoPresent>
                                   <url></url>
                               </video>
                        </item>
                        <item label="System Status">
                            <images>
                                <img url="images/APX32-systemStatus_01.png"/>
                                <img url="images/APX32-systemStatus_02.png"/>
                            </images>
                            <video>
                                <videoPresent>false</videoPresent>
                                   <url></url>
                               </video>
                        </item>
                    </userOptions>
                      <troubleShooting>
                        <item label="AC Loss">
                            <images>
                                <img url="images/APX32-noAC_01.png"/>
                                <img url="images/APX32-noAC_02.png"/>
                            </images>
                            <video>
                                <videoPresent>false</videoPresent>
                                   <url></url>
                               </video>
                        </item>
                        <item label="AC Loss">
                            <images>
                                <img url="images/APX32-noAC_01.png"/>
                                <img url="images/APX32-noAC_02.png"/>
                            </images>
                            <video>
                                <videoPresent>false</videoPresent>
                                   <url></url>
                               </video>
                        </item>
                      </troubleShooting>
               </apx32>
            </menu>

            • 4. Re: cannot access a property or method of a null object reference
              mewk Level 3

              the data for the two lists is quite different; make sure the item renderer isn't expecting data that never gets passed in.

               

              can't say more w/o checking your "listRenderer."

               

              - e

              • 5. Re: cannot access a property or method of a null object reference
                cyber0897 Level 1

                i dont think it is...

                if you like i have attached all the relevant code for this

                 

                the apx32Troubleshoot.mxml:

                 

                <?xml version="1.0" encoding="utf-8"?>
                <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
                         xmlns:s="library://ns.adobe.com/flex/spark"
                         xmlns:mx="library://ns.adobe.com/flex/halo" width="975" height="400"
                         creationComplete="app_creationComplete(event)">
                    <fx:Script source="apx32Action.as" />
                    <fx:Style>
                        @namespace s "library://ns.adobe.com/flex/spark";
                        @namespace mx "library://ns.adobe.com/flex/halo";
                        .nextButton{
                            fontSize:12;
                            textRollOverColor:#333333;
                            fontFamily:dinb;
                            fontLookup: embeddedCFF;
                        }
                    </fx:Style>
                    <mx:HBox>
                        <mx:TabNavigator width="275" height="400" paddingTop="0" tabWidth="137.5">
                            <mx:VBox label="USER OPTIONS" width="100%" height="100%" horizontalScrollPolicy="off" verticalScrollPolicy="off">
                                <s:List id="userOptions" width="100%" height="100%" itemRenderer="modules.apx32.myComponents.listRenderer"
                                        borderAlpha="0" contentBackgroundColor="#e9e9e9" change="userOptionsChange(event)">
                                </s:List>
                            </mx:VBox>
                            <mx:VBox label="TROUBLESHOOTING">
                                <s:List id="trouble" width="100%" height="100%" itemRenderer="modules.apx32.myComponents.listRenderer"
                                        borderAlpha="0">
                                </s:List>
                            </mx:VBox>
                        </mx:TabNavigator>

                    </mx:HBox>
                    <mx:Image id="definition" width="700" height="375" x="275" y="24" />
                    <mx:LinkButton label="More Options" id="next" skin="{null}" x="830" y="371" visible="false" />
                </s:Group>

                 

                 

                listRenderer.mxml: (my item renderer)

                 

                <?xml version="1.0" encoding="utf-8"?>
                <s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
                                xmlns:s="library://ns.adobe.com/flex/spark"
                                xmlns:mx="library://ns.adobe.com/flex/halo" height="40">

                 

                    <s:states>
                        <s:State name="normal" />
                        <s:State name="hovered" stateGroups="[hoveredStates]" />
                        <s:State name="selected" stateGroups="[selectedStates]" />
                        <s:State name="normalAndShowsCaret" />
                        <s:State name="hoveredAndShowsCaret" stateGroups="[hoveredStates]" />
                        <s:State name="selectedAndShowsCaret" stateGroups="[selectedStates]" />
                    </s:states>
                   
                    <s:Rect left="0" bottom="1" right="1" height="2">
                        <s:fill>
                            <s:SolidColor color="0x000000" alpha=".2"/>
                        </s:fill>
                    </s:Rect>

                 

                    <s:Rect width="100%" height="100%">
                        <s:fill>
                            <s:SolidColor color="0x6699cc" alpha="0" alpha.hoveredStates="#2c9fe1" alpha.selectedStates="#2c9fe1" />
                        </s:fill>
                    </s:Rect>
                        <mx:Label text="{data.label}" textAlign="center" x="75" verticalCenter=".5"
                                  color.normal="blue" color.hovered="#ffffff"/>
                        <mx:Image source="@Embed(source='../images/dottedDivider.gif')"  x="0" y="38"/>
                   
                </s:ItemRenderer>

                 

                 

                 

                and my actionscript to run this...


                apx32Action.as:

                 

                 

                // ActionScript file
                    import mx.controls.Alert;
                    import mx.core.ScrollPolicy;
                    import mx.events.FlexEvent;
                    import mx.rpc.events.FaultEvent;
                    import mx.rpc.events.ResultEvent;
                    import mx.rpc.http.HTTPService;
                   
                    import spark.events.IndexChangeEvent;

                 

                   
                    [Bindable] private var menuXml:XML;
                    [Bindable] private var imgList:Object = new Object();
                    [Bindable] private var xmlReturn:Object;
                    private var currImage:int = 0;
                    [Bindable] public var imgClass:Class;
                    [Bindable] public var imgUrl:String;

                 

                    private function myXml_resultHandeler(event:ResultEvent):void{
                        var resultData:Object = event.result;
                        xmlReturn = resultData;
                        userOptions.dataProvider = resultData.menu.apx32.userOptions.item;
                        //trouble.dataProvider = xmlReturn.menu.apx32.troubleShooting.item;

                 

                       
                //        xmlMainMenu.source = event.result.children();
                        //var test:String;
                    }
                    private function myXml_faultHandler(event:FaultEvent):void{
                        Alert.show("Error loading XML");
                        Alert.show(event.fault.message);
                    }
                    private function app_creationComplete(event:FlexEvent):void{
                        userOptions.scroller.setStyle("horizontalScrollPolicy", ScrollPolicy.OFF);
                        //trouble.scroller.setStyle("horizontalScrollPolicy", ScrollPolicy.OFF);
                       
                       
                        var myXml:HTTPService = new HTTPService();
                        myXml.url = "modules/apx32/apx32TroubleshootingXml.xml";
                        myXml.resultFormat = "object";
                        myXml.addEventListener(ResultEvent.RESULT, myXml_resultHandeler);
                        myXml.addEventListener(FaultEvent.FAULT, myXml_faultHandler);
                        myXml.send();
                    }
                    private function userOptionsChange(event:IndexChangeEvent):void{
                        currImage = 1;
                        imgList = event.currentTarget.selectedItems[0].images.url;
                        //definition.source = imgList[currImage];
                        imgUrl = imgList[currImage];
                        //definition.source = 'images/APX32-adjustingVolume_01.png';
                        next.visible = true;
                    }

                 

                 

                 

                i use the same item renderer for both user Options, and troubleshooting... since everythign shuold just be in the source...

                im at a complete loss right now  lol

                 

                and thanks mewk...

                • 6. Re: cannot access a property or method of a null object reference
                  mewk Level 3

                  cyber,

                  The default creation policy for all containers, except the Application container, is the policy of the parent container. The default policy for the Application container is auto. In most cases, therefore, the View Stack TabNavigator control’s children are not created until they are selected. You cannot...

                  so

                   

                  <mx:TabNavigator creationPolicy="all">
                  

                   

                   

                   

                  There's also an error here

                  imgList = event.currentTarget.selectedItems[0].images.url;
                  

                  you need to keep walking the chain.

                   

                   

                  best o luck ,

                   

                  - e

                  • 7. Re: cannot access a property or method of a null object reference
                    cyber0897 Level 1

                    AHA!!! that worked PERFECTLY!!! htank you soo much for the explaination!! I really appretiate it!!

                     

                     

                    and the error line...

                    imgList = event.currentTarget.selectedItems[0].images.url;

                    i have no idea what the error is... ? lol... ive been trying to get the image to display on my application when i click the list item

                    ive tried things like

                     

                    description.source = event.currentTarget.selectedItems[0].image.@url;

                    and that line seems to give me an error....

                     

                    any ideas on that?

                    • 8. Re: cannot access a property or method of a null object reference
                      mewk Level 3

                      try

                      private function userOptionsChange(event:IndexChangeEvent):void{
                        currImage = 1;
                        imgList = event.currentTarget.selectedItems[0].images.img;
                        definition.source = imgList[currImage]["url"];
                        next.visible = true;
                      }
                      

                       

                      - e

                      • 9. Re: cannot access a property or method of a null object reference
                        cyber0897 Level 1

                        hey mewk.. ty for all your help!!! i finally got it working !

                         

                        the update code ended up being

                         

                            private function userOptionsChange(event:IndexChangeEvent):void{
                                currImage = 0;
                                imgList.source = userOptionProvider[event.newIndex].images.children();
                                definition.source = imgList[currImage].@url;

                         

                            }

                         


                        had to change most of my code... but the main difference was to change my xml resultFormat to e4x instead of object