Skip navigation
Currently Being Moderated

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

Mar 11, 2013 2:24 AM

Tags: #error #flex #actionscript #list



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



                    title="Endikasyona Göre Sorgulama">










                              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




                                        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.tex t,basInt.toString(),bitInt.toString());










                              protected function geri_clickHandler(event:MouseEvent):void





                                        if( basInt > 0 )


                                                  basInt -= 50;

                                                  bitInt -= 50;


                                                  endikasyonAdiListesiGetir(endikasyonadTI.tex t,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(RehberMobilEtkinMaddeSorgulama Sonuc,endList,"endikasyon");




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










                                        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\Desktop\RehberTablet\src\views\RehberMobilEtkinMaddeS orgulamaEndikasyon.mxml:115]

          at views::RehberMobilEtkinMaddeSorgulamaEndikasyon/__sorgula_click()[C:\ Users\ToDem\Desktop\RehberTablet\src\views\RehberMobilEtkinMaddeSorgul amaEndikasyon.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.



  • Currently Being Moderated
    Mar 11, 2013 6:32 AM   in reply to Mert AKINCI

    It's a huge wall of text.

    I'm pretty sure you get no answers because people just see this code, turn around, and walk away.


    Your error is in that sorgula_clickHandler function.

    It has 4 lines of code.

    Put some traces around there and see exactly what line gives you that error (hint: it's when you stop seeing traces).

    Then see which object can be null (the error pops when you try to get a property/method of a null object).

    So it's obviously either endList[i] in the 'for' loop, or navigator.

    Put some work into it.

    Mark as:
  • Currently Being Moderated
    Mar 11, 2013 7:01 AM   in reply to Mert AKINCI

    Try using the debugger, put in some breakpoints and step through the code and investigate the variable values as you proceed.

    Mark as:
  • Currently Being Moderated
    Mar 11, 2013 7:59 AM   in reply to Mert AKINCI

    Or maybe 'navigator' is null?

    I don't see it defined anywhere, and View doesn't have this property, as far as adobe help tells me.

    Mark as:
  • Currently Being Moderated
    Mar 11, 2013 8:24 AM   in reply to Mert AKINCI

    Mert, stop guessing and use the debugger.


    Objects in actionscript are created in the same kind of way as Java.

    Mark as:
  • Currently Being Moderated
    Mar 11, 2013 8:25 AM   in reply to Mert AKINCI

    You can just use Array instead of Vector.<Object>, there's no difference performance wise.

    And there's nothing wrong with the initialization of that vector.

    But please, can you



    navigator.pushView(RehberMobilEtkinMaddeSorgulama Sonuc,endList,"endikasyon");\


    If it's not null, i give up.

    (but it should be)

    Mark as:
  • Currently Being Moderated
    Mar 11, 2013 8:35 AM   in reply to LucasAlex

    The stack dump shows you a line number.  What line of code is at that line number and why can its elements be null?

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points