11 Replies Latest reply on Mar 12, 2013 6:07 AM by Mert AKINCI

    Cannot access a property or method of a null object reference.

    Mert AKINCI



      I want to select more than one (allowMultipleSelection=true) record from a list and then when i click Sorgula(Search) button, i want it to show me the results related to the items that i selected from the list. But it gives me an error.


      The code is below;


      <?xml version="1.0" encoding="utf-8"?>

      <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"



                          title="Endikasyona Göre Sorgulama">





                                    import mx.events.FlexEvent;


                                    import spark.events.GridSelectionEvent;

                                    import spark.events.IndexChangeEvent;


                                    import valueObjects.EndikasyonAd;



                                    public var basInt:int = 0;

                                    public var bitInt:int = 50;

                                    public var bas:String = "0";

                                    public var bit:String = "50";



                                    public var endObj:EndikasyonAd = null;


                                    public var myDataObject:Object = null;


                                    public var endList:Vector.<Object> = new Vector.<Object>();


                                    protected function geriDonClick(event:MouseEvent):void





                                    protected function anaSayfaClick(event:MouseEvent):void







                                    protected function endikasyonadTI_keyUpHandler(event:KeyboardEvent):void








                                              /*endikasyon_list.selectedIndex = -1;*/





                                    protected function endikasyonAdiListesiGetir(basHarf:String, baslangic:String, bitis:String):void


                                              endikasyonAdiListesiGetirResult.token = ilacSorgulama.endikasyonAdiListesiGetir(basHarf, baslangic, bitis);






                                    protected function ileri_clickHandler(event:MouseEvent):void




                                              if( bitInt < parseInt(endikasyonAdiListesiGetirResult.lastResult[0].count) )


                                                        basInt += 50;

                                                        bitInt += 50;



                                                        endikasyonAdiListesiGetir(endikasyonadTI.text,basInt.toString(), bitInt.toString());










                                    protected function geri_clickHandler(event:MouseEvent):void





                                              if( basInt > 0 )


                                                        basInt -= 50;

                                                        bitInt -= 50;


                                                        endikasyonAdiListesiGetir(endikasyonadTI.text,basInt.toString(), bitInt.toString());










                                    protected function sorgula_clickHandler(event:MouseEvent):void



                                              var obj:Object = new Object();

                                              /*var fList:Vector.<Object> = new Vector.<Object>();




                                              fList = firma_list.selectedItems;*/


                                              /*trace(fList[0].id +"  "+ fList[1].id +"\n"+

                                              fList[0].firmaAd +"  "+ fList[1].firmaAd );*/




                                              for(var i:int = 0; i < endList.length ; i++)


                                                        trace(endList[i].id + "\n"+ endList[i].ad);



                                              navigator.pushView(RehberMobilEtkinMaddeSorgulamaSonuc,endList,"endik asyon");




                                    protected function endikasyon_list_clickHandler(event:MouseEvent):void


                                              /*var lst:Vector.<Object> = new Vector.<Object>();






                                              /*fList = firma_list.selectedItems;*/


                                              if(endList == null)



                                              endList          = new Vector.<EndikasyonAd>();




                                              endObj = new EndikasyonAd();


                                              endObj.ad = endikasyon_list.selectedItem.ad;


                                              endObj.id = endikasyon_list.selectedItem.id;






                                              trace("PUSH= " + endList.push(endObj));*/





                                              trace("Length of ENDLIST= " + endList.length);


                                              for(var p:int = 0 ; p < endList.length ; p++)


                                                        trace("ENDLIST= " + endList[p] + " p= " + p);






                                              trace("Endikasyon_list selected indices: " + endikasyon_list.selectedIndices);














                          <s:CallResponder id="endikasyonAdiListesiGetirResult"/>

                          <ilacsorgulama:IlacSorgulama id="ilacSorgulama"/>

                          <!-- Place non-visual elements (e.g., services, value objects) here -->




                          <s:State name="portrait" />

                          <s:State name="landscape" />





                          <s:Button width="100" label="Geri Dön" click="geriDonClick(event)"/>



                          <s:Button id="sorgula" label="Sorgula"


                          <s:Button width="100" label="Ana Sayfa" click="anaSayfaClick(event)"/>



                <s:Label x="0" y="0" width="100%" height="50" styleName="todem"/>

                <s:Label x="0" y="909" width="100%" height="50" styleName="todem"

                                     x.portrait="0" y.portrait="909"/>

                <s:Button id="geri" x="173" y="913" width="100" label="Geri" click="geri_clickHandler(event)"


                                      x.portrait="132" y.portrait="913" height.portrait="42"/>

                <s:Button id="ileri" x="505" y="913" width="100" label="İleri" click="ileri_clickHandler(event)"


                                      x.portrait="524" y.portrait="913" height.portrait="42"/>

                <s:Label includeIn="landscape" x="312" y="917" width="154" height="36" color="#FFFFFF"

                                     text="Sayfa  1/5" textAlign="center" verticalAlign="middle"/>

                <s:Label x="0" y="49" width="100%" height="30" styleName="todemacik" text="Endikasyon ismi giriniz."/>

                <s:TextInput id="endikasyonadTI" x="23" y="8" width="642" height="34"



                <s:Button x="685" y="8" width="70" height="34" label="Ara"

                                      x.landscape="938" y.landscape="8"/>

                <s:List id="endikasyon_list"  labelField="ad" allowMultipleSelection="true" click="endikasyon_list_clickHandler(event)"

                                    x.landscape="0" y.landscape="79" width.landscape="1024" height.landscape="575"

                                    x.portrait="0" y.portrait="79" width.portrait="768" height.portrait="831">

                          <s:AsyncListView list="{endikasyonAdiListesiGetirResult.lastResult}"/>





      The given error is:

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

                at views::RehberMobilEtkinMaddeSorgulamaEndikasyon/sorgula_clickHandler()[C:\Users\ToDem\Des ktop\RehberTablet\src\views\RehberMobilEtkinMaddeSorgulamaEndikasyon.mxml:115]

                at views::RehberMobilEtkinMaddeSorgulamaEndikasyon/__sorgula_click()[C:\Users\ToDem\Desktop\ RehberTablet\src\views\RehberMobilEtkinMaddeSorgulamaEndikasyon.mxml:193]


      What I'm trying to do is just creating a Vector.<Object> at the top and use it by adding items whenever i click an item on the list. I want every item clicked added on the Vector so that i can pass this vector to result view and use it there.

      But even if i create the vector, it always says vector is null before it adds new item to it. First it says it is null then it adds items. At the end it gives above error which is about null object etc.


      I've been dealing with this issue for few weeks. And i can't make project move on since i couldn't find any solutions.


      Hope i could mention it clearly.


      Any helps would be appreciated.


      Thanks in Advance.