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

      Hi,

       

      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"

                          xmlns:s="library://ns.adobe.com/flex/spark"

                          xmlns:ilacsorgulama="services.ilacsorgulama.*"

                          title="Endikasyona Göre Sorgulama">

       

       

                <fx:Script>

                          <![CDATA[

                                    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

                                    {

                                              navigator.popView();

                                    }

       

                                    protected function anaSayfaClick(event:MouseEvent):void

                                    {

                                              navigator.popToFirstView();

                                    }

       

       

       

                                    protected function endikasyonadTI_keyUpHandler(event:KeyboardEvent):void

                                    {

       

       

                                              endikasyonAdiListesiGetir(endikasyonadTI.text,bas,bit);

       

       

       

                                              /*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());

                                              }

       

       

       

                                              trace(basInt);

                                              trace(bitInt);

       

                                    }

       

                                    protected function geri_clickHandler(event:MouseEvent):void

                                    {

       

       

       

                                              if( basInt > 0 )

                                              {

                                                        basInt -= 50;

                                                        bitInt -= 50;

       

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

                                              }

       

       

       

                                              trace(basInt);

                                              trace(bitInt);

       

                                    }

       

                                    protected function sorgula_clickHandler(event:MouseEvent):void

                                    {

       

                                              var obj:Object = new Object();

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

       

                                              trace(firma_list.selectedIndices);

       

                                              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>();

       

                                              lst.push(firma_list.selectedItems);

       

                                              trace(lst);*/

       

                                              /*fList = firma_list.selectedItems;*/

                                              /*

                                              if(endList == null)

                                              {

       

                                              endList          = new Vector.<EndikasyonAd>();

       

                                              }

       

                                              endObj = new EndikasyonAd();

       

                                              endObj.ad = endikasyon_list.selectedItem.ad;

                                              trace(endikasyon_list.selectedItem.ad);

                                              endObj.id = endikasyon_list.selectedItem.id;

                                              trace(endikasyon_list.selectedItem.id);

       

       

                                              endList.push(endObj);

       

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

       

                                              endList.push(endikasyon_list.selectedItem);

       

                                              trace(endikasyon_list.selectedItem);

                                              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);

       

       

       

                                    }

       

       

       

       

                          ]]>

                </fx:Script>

       

       

                <fx:Declarations>

                          <s:CallResponder id="endikasyonAdiListesiGetirResult"/>

                          <ilacsorgulama:IlacSorgulama id="ilacSorgulama"/>

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

                </fx:Declarations>

       

                <s:states>

                          <s:State name="portrait" />

                          <s:State name="landscape" />

                </s:states>

       

       

                <s:navigationContent>

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

                </s:navigationContent>

                <s:actionContent>

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

                                                click="sorgula_clickHandler(event)"/>

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

                </s:actionContent>

       

                <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)"

                                      width.landscape="200"

                                      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)"

                                      width.landscape="200"

                                      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"

                                               keyUp="endikasyonadTI_keyUpHandler(event)"

                                               width.landscape="901"/>

                <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}"/>

                </s:List>

       

      </s:View>

       

      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.

       

      Mert.