Adobe Flex错误TypeError:错误#1009:无法访问空对象引用的属性或方法

时间:2011-06-28 20:27:24

标签: flash flex adobe builder

我正在尝试将搜索字段添加到Adobe Flex项目中,当您键入新创建的搜索字段时,我收到以下错误:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at flextest/filterDecalMyArrayCollection()
    at mx.collections::ListCollectionView/internalRefresh()
    at mx.collections::ListCollectionView/refresh()
    at flextest/filterDecal()
    at flextest/__searchDecal_change()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.core::UIComponent/dispatchEvent()
    at mx.controls::TextInput/textField_changeHandler()

非常感谢任何帮助!

以下是我在Flex项目中的代码:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
                initialize="doSend()" 
                layout="absolute" width="1092" height="834">
    <mx:Style source="flextest.css"/>
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.events.ListEvent;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;
            import mx.rpc.http.HTTPService;

            [Bindable]
            private var datalist:ArrayCollection;
            private var rowcount;
            private var firstTimeID:Boolean = true;
            private var firstTimeName:Boolean = true;
            private var firstTimeDL:Boolean = true;
            private var firstTimeDecal:Boolean = true;
            private var firstTimeTag:Boolean = true;

            private function resultHandler(event:ResultEvent):void{                
                datalist = event.result.data.row;
                rowcount = event.result.data.numrows;
                /* if(rowcount == '1'){
                datalist.removeItemAt(1); */ 
            }
            public function doSend():void {
                xmlFromDatabase.url = "http://webprod.jsu.edu/pd/guestxml.php?t=" + new Date().getTime();
                xmlFromDatabase.send();

            }
            private function onItemClick( e:ListEvent ):void {
                var dlAdjust;

                txtTuid.text = e.itemRenderer.data.TUID;
                txtStudentName.text = e.itemRenderer.data.STUDENTNAME;
                txtDecalYear.text = e.itemRenderer.data.DECALYEAR;
                txtDecalType.text = e.itemRenderer.data.DECALTYPE;
                txtConfNo.text = e.itemRenderer.data.DECALNUMBER;
                txtDecNo.text = e.itemRenderer.data.DECALNUMPERM;
                if (e.itemRenderer.data.DECALCAT == "WHIT") {
                    cmbCategory.selectedIndex = 0;
                }  else {
                    cmbCategory.selectedIndex = -1;
                }
                txtOriginalDate.text = e.itemRenderer.data.ORIGDATE;
                txtUpdateDate.text = e.itemRenderer.data.UPDTDATE;
                txtNote.text = e.itemRenderer.data.DECALNOTES;
                dlAdjust = e.itemRenderer.data.DLNUM;
                txtDLic.text = dlAdjust.slice(0, dlAdjust.length - 2); 
                txtDLState.text = e.itemRenderer.data.DLSTATE;
                txtVMake.text = e.itemRenderer.data.VMAKE;
                txtVModel.text = e.itemRenderer.data.VMODEL;
                txtVBody.text = e.itemRenderer.data.VBODY;
                txtVColor.text = e.itemRenderer.data.VCOLOR;
                txtVTag.text = e.itemRenderer.data.VTAG;
                txtVState.text = e.itemRenderer.data.VSTATE;
                txtVYear.text = e.itemRenderer.data.VYEAR;
                txtVCounty.text = e.itemRenderer.data.VCOUNTY;
                txtVIns.text = e.itemRenderer.data.VINS;
                if (e.itemRenderer.data.VPMT == "A") {
                    cmbPayment.selectedIndex = 0;
                } else if  (e.itemRenderer.data.VPMT == "T"){
                    cmbPayment.selectedIndex = 1;
                } else {
                    cmbPayment.selectedIndex = -1;
                }
                txtPhone.text = e.itemRenderer.data.PHONE;
                if (e.itemRenderer.data.DECALVOIDED == "V") {
                    chkVoid.selected = true;
                    lblVoidValue.label = "Void";
                } else {
                    chkVoid.selected = false;
                    lblVoidValue.label = null;
                }
                if (e.itemRenderer.data.ADDITIONAL == "A") {
                    chkAdditional.selected = true;
                    lblAdditional.label = "Additional";
                } else {
                    chkAdditional.selected = false;
                    lblAdditional.label = null;

                }
            }


            public function handleResult(event:ResultEvent):void {
                /*var urlRequest:URLRequest = new URLRequest('http://webprod.jsu.edu/pd-test/admin/flextest.html');
                navigateToURL(urlRequest,"_self");*/                
            }
            public   function handleFault(event:FaultEvent):void {
            }


            private function filterTag():void {
            datalist.filterFunction = filterTagMyArrayCollection;
            datalist.refresh();
            }           
            private function filterTagMyArrayCollection(item:Object):Boolean {
            var searchString:String = searchTag.text.toLowerCase();
            var itemName:String = (item.VTAG as String).toLowerCase();
            return itemName.indexOf(searchString) > -1;
            }
            private function filterDL():void {
            datalist.filterFunction = filterDLMyArrayCollection;
            datalist.refresh();
            }           
            private function filterDLMyArrayCollection(item:Object):Boolean {
            var searchString:String = searchDL.text;
            var itemName:String = (item.DLNUM as String);
            return itemName.indexOf(searchString) > -1;
            }

            private function filterDecal():void {
                datalist.filterFunction = filterDecalMyArrayCollection;
                datalist.refresh();
            }

            private function filterDecalMyArrayCollection(item:Object):Boolean {
                var searchString:String = searchDecal.text;
                var itemName:String = (item.DECALNUMPERM as String);
                return itemName.indexOf(searchString) > -1;
            }

            /*private function filterID():void {
                datalist.filterFunction = filterIDMyArrayCollection;
                datalist.refresh();
            }           
            private function filterIDMyArrayCollection(item:Object):Boolean {
                var searchString:String = searchID.text.toLowerCase();
                var itemName:String = (item.STUDENTPIDM as String).toLowerCase();
                return itemName.indexOf(searchString) > -1;
            }       */      
            private function filterName():void {
                datalist.filterFunction = filterNameMyArrayCollection;
                datalist.refresh();
            }           
            private function filterNameMyArrayCollection(item:Object):Boolean {
                var searchString:String = searchName.text.toLowerCase();
                var itemName:String = (item.STUDENTNAME as String).toLowerCase();
                return itemName.indexOf(searchString) > -1;
            }           

            private function clearNameTextInput():void {                
                if (firstTimeName == true )
                {
                    searchName.text = "";
                    firstTimeName = false;
                }
            }   


            /*  
            private function clearIDTextInput():void {              
            if (firstTimeID == true )
            {
            searchID.text = "";
            firstTimeID = false;
            }   
            }       */      
            private function clearDLTextInput():void {              
            if (firstTimeDL == true )
            {
            searchDL.text = "";
            firstTimeDL = false;
            }
            }           
            private function clearTagTextInput():void {             
            if (firstTimeTag == true )
            {
            searchTag.text = "";
            firstTimeTag = false;
            }
            }

            private function clearDecalTextInput():void {               
                if (firstTimeDecal == true )
                {
                    searchDecal.text = "";
                    firstTimeDecal = false;
                }
            } 


            protected function button1_clickHandler(event:MouseEvent):void
            {
                //What happens when we click the refresh button
                var urlRequest:URLRequest = new URLRequest('http://webprod.jsu.edu/pd-test/guest/whiteadmin.php');
                navigateToURL(urlRequest,"_self");
            }
            protected function btnSave_clickHandler(event:MouseEvent):void
            {
                //What happens when we click the save button
                form1.send();               
            }
            protected function chkVoid_clickHandler(event:MouseEvent):void
            {
                //What happens when we click Void Checkbox
                if (chkVoid.selected.valueOf() == true) {
                    lblVoidValue.label = "Void";
                } else {
                    lblVoidValue.label = null;
                }
            }
            protected function chkAdditional_clickHandler(event:MouseEvent):void
            {
                // What happens when we click Additional Checkbox
                if (chkAdditional.selected.valueOf() == true) {
                    lblAdditional.label = "Additional";
                } else {
                    lblAdditional.label = null;
                }
            }




            protected function button3_clickHandler(event:MouseEvent):void
            {
                //What happens when we click the register white button
                var urlRequest:URLRequest = new URLRequest('http://webprod.jsu.edu/pd-test/registerwhite.php');
                navigateToURL(urlRequest,"_self");
            }

            protected function button4_clickHandler(event:MouseEvent):void
            {
                // TODO Auto-generated method stub
                var urlRequest:URLRequest = new URLRequest('http://webprod.jsu.edu/pd-test/admin/dispatch.php');
                navigateToURL(urlRequest,"_self");
            }

            protected function dg_changeHandler(event:ListEvent):void
            {
                // TODO Auto-generated method stub
            }
        ]]>
    </mx:Script>


    <!-- Service Calls -->
    <mx:HTTPService url="http://webprod.jsu.edu/pd-test/guestxml.php"
                    id="xmlFromDatabase" 
                    showBusyCursor="true" 
                    result="resultHandler(event)"                   
                    method="POST" >
    </mx:HTTPService>

    <mx:HTTPService id="form1" 
                    url="http://webprod.jsu.edu/pd-test/guestupdate.php"                    
                    method="POST"
                    result="handleResult(event)"
                    resultFormat="text" >
        <mx:request>
            <txtTuid>
                {txtTuid.text}
            </txtTuid>
            <txtStudentName>
                {txtStudentName.text}
            </txtStudentName>
            <txtDecalYear>
                {txtDecalYear.text}
            </txtDecalYear>
            <txtDecalType>
                {txtDecalType.text}
            </txtDecalType>
            <txtConfNo>
                {txtConfNo.text}
            </txtConfNo>
            <txtDecNo>
                {txtDecNo.text}
            </txtDecNo>
            <txtCategory>
                {cmbCategory.selectedItem.data}
            </txtCategory>
            <dateOrigDate>
                {txtOriginalDate.text}
            </dateOrigDate>
            <txtNote>
                {txtNote.text}
            </txtNote>
            <txtDLic>
                {txtDLic.text}
            </txtDLic>
            <txtDLState>
                {txtDLState.text}
            </txtDLState>
            <txtVMake>
                {txtVMake.text}
            </txtVMake>
            <txtVModel>
                {txtVModel.text}
            </txtVModel>
            <txtVBody>
                {txtVBody.text}
            </txtVBody>
            <txtVColor>
                {txtVColor.text}
            </txtVColor>
            <txtVTag>
                {txtVTag.text}
            </txtVTag>
            <txtVState>
                {txtVState.text}
            </txtVState>
            <txtVYear>
                {txtVYear.text}
            </txtVYear>
            <txtVCounty>
                {txtVCounty.text}
            </txtVCounty>
            <txtVIns>
                {txtVIns.text}
            </txtVIns>
            <txtVPmt>
                {cmbPayment.selectedItem.data}
            </txtVPmt>
            <txtPhone>
                {txtPhone.text}
            </txtPhone>
            <lblVoidValue>
                {lblVoidValue.label}
            </lblVoidValue>
            <lblAdditional>
                {lblAdditional.label}
            </lblAdditional>
        </mx:request>
    </mx:HTTPService>

    <mx:Label x="6" y="4" text="White Decal Dispatch" fontWeight="bold" color="#CC3333" fontSize="30"/>

    <mx:DataGrid x="10" y="53" dataProvider="{datalist}" id="dg" itemClick="onItemClick( event );" height="255" width="1009" change="dg_changeHandler(event)">
        <mx:columns>
            <!--<mx:DataGridColumn width="50" headerText="uid" dataField="TUID"/>-->
            <mx:DataGridColumn width="30" headerText="Year" dataField="DECALYEAR"/>
            <mx:DataGridColumn width="80"  headerText="Name" dataField="STUDENTNAME"/>
            <mx:DataGridColumn width="23" headerText="Conf #." dataField="DECALNUMBER"/>
            <mx:DataGridColumn width="23" headerText="Decal #" dataField="DECALNUMPERM"/>
            <mx:DataGridColumn width="10" headerText="Typ" dataField="DECALTYPE"/>
            <mx:DataGridColumn width="20" headerText="Cat" dataField="DECALCAT"/>
            <mx:DataGridColumn width="30" headerText="dlnum" dataField="DLNUM"/>
            <mx:DataGridColumn width="12" headerText="dlstate" dataField="DLSTATE"/>
            <mx:DataGridColumn width="20" headerText="Make" dataField="VMAKE"/>
            <mx:DataGridColumn width="30" headerText="Model" dataField="VMODEL"/>
            <mx:DataGridColumn width="12" headerText="Body" dataField="VBODY"/>
            <mx:DataGridColumn width="15" headerText="Year" dataField="VYEAR"/>
            <mx:DataGridColumn width="10" headerText="Color" dataField="VCOLOR"/>
            <mx:DataGridColumn width="30" headerText="Tag" dataField="VTAG"/>
            <mx:DataGridColumn width="12" headerText="State" dataField="VSTATE"/>
            <mx:DataGridColumn width="30" headerText="County" dataField="VCOUNTY"/><!--
            <mx:DataGridColumn width="50" headerText="Ins" dataField="VINS"/>
            <mx:DataGridColumn width="20" headerText="Pmt" dataField="VPMT"/>-->
            <mx:DataGridColumn width="5" headerText="Rec" dataField="DECALPICKEDUP"/>
            <!--<mx:DataGridColumn width="20" headerText="decalvoided" dataField="DECALVOIDED"/>
            <mx:DataGridColumn width="50" headerText="origdate" dataField="ORIGDATE"/>
            <mx:DataGridColumn width="50" headerText="updtdate" dataField="UPDTDATE"/>
            <mx:DataGridColumn width="20" headerText="charged" dataField="CHARGED"/>
            <mx:DataGridColumn width="50" headerText="chargedate" dataField="CHARGEDATE"/>
            <mx:DataGridColumn width="50" headerText="decalnotes" dataField="DECALNOTES"/>-->
        </mx:columns>
    </mx:DataGrid>
    <mx:Form id= "frmUpdateDecal" x="710" y="336" width="309" height="363">
        <mx:FormItem label="DLic#">
            <mx:TextInput id="txtDLic" maxChars="20"/>
        </mx:FormItem>
        <mx:FormItem label="DLic State:">
            <mx:TextInput id="txtDLState" maxChars="2"/>
        </mx:FormItem>
        <mx:FormItem label="Vehicle Make:">
            <mx:TextInput id="txtVMake" maxChars="4"/>
        </mx:FormItem>
        <mx:FormItem label="Vehicle Model:">
            <mx:TextInput id="txtVModel" maxChars="20"/>
        </mx:FormItem>
        <mx:FormItem label="Vehicle Body:">
            <mx:TextInput id="txtVBody" maxChars="4"/>
        </mx:FormItem>
        <mx:FormItem label="Vehicle Color:">
            <mx:TextInput id="txtVColor" maxChars="3"/>
        </mx:FormItem>
        <mx:FormItem label="Vehicle Tag:">
            <mx:TextInput id="txtVTag" maxChars="20"/>
        </mx:FormItem>
        <mx:FormItem label="Tag State:">
            <mx:TextInput id="txtVState" maxChars="2"/>
        </mx:FormItem>
        <mx:FormItem label="Vehicle Year:">
            <mx:TextInput id="txtVYear" maxChars="4"/>
        </mx:FormItem>
        <mx:FormItem label="Tag County:">
            <mx:TextInput id="txtVCounty" maxChars="20"/>
        </mx:FormItem>
        <mx:FormItem label="Insurance:">
            <mx:TextInput id="txtVIns" maxChars="50"/>
        </mx:FormItem>
        <mx:FormItem label="Phone:">
            <mx:TextInput id="txtPhone" maxChars="11"/>
        </mx:FormItem>
    </mx:Form>
    <mx:Button x="539" y="725" label="Refresh" width="156" click="button1_clickHandler(event)"/>
    <mx:Button x="710" y="17" label="Add White Decal" width="117" click="button3_clickHandler(event)"/>
    <mx:ApplicationControlBar x="10" y="365" width="261" height="334">
        <mx:Form height="268" width="236" y="25">           
            <mx:FormItem>
                <mx:Label text="Name:" color="#CC3333" fontWeight="bold" fontStyle="italic" textDecoration="underline"/>
            </mx:FormItem>
            <mx:TextInput id="searchName" change="filterName()" 
                          enabled="true" 
                          focusIn="clearNameTextInput()" 
                          text="Filter/Search Name"
                          width="202" height="26" color="#2B4381"/>         
            <mx:FormItem>
                <mx:Label text="Tag:" color="#CC3333" fontWeight="bold" fontStyle="italic" textDecoration="underline"/>
            </mx:FormItem>
            <!--
            <mx:TextInput id="searchID" change="filterID()" 
            enabled="true" 
            focusIn="clearIDTextInput()" 
            text="Filter/Search JSU ID"
            width="204" height="26" color="#2B4381"/>   -->     

            <mx:TextInput id="searchTag" change="filterTag()" 
            enabled="true" 
            focusIn="clearTagTextInput()" 
            text="Filter/Search Tag"
            width="201" height="26" color="#2B4381"/>




            <mx:FormItem>
                <mx:Label text="Driver's License:" color="#CC3333" fontWeight="bold" fontStyle="italic" textDecoration="underline"/>
            </mx:FormItem>
            <mx:TextInput id="searchDL" change="filterDL()" 
            enabled="true" 
            focusIn="clearDLTextInput()" 
            text="Filter/Search Driver's License"
            width="200" height="26" color="#2B4381"/>

            <mx:FormItem>
                <mx:Label text="Decal Number:" color="#CC3333" fontWeight="bold" fontStyle="italic" textDecoration="underline"/>
            </mx:FormItem>

            <mx:TextInput id="searchDecal" change="filterDecal()" 
                          enabled="true" 
                          focusIn="clearDecalTextInput()" 
                          text="Filter/Search Decal Number"
                          width="200" height="26" color="#2B4381"/>

        </mx:Form>  

    </mx:ApplicationControlBar> 
    <mx:FormItem label="Confirmation No:" x="299" y="403" width="219" fontStyle="italic">
        <mx:TextInput id="txtConfNo" width="119" editable="false" contentBackgroundAlpha="1.0" dropShadowVisible="false" borderVisible="false" color="#CC3333" maxChars="5"/>
    </mx:FormItem>
    <mx:FormItem label="System Tranaction ID:" x="276" y="426" width="240" fontStyle="italic">
        <mx:TextInput id="txtTuid" width="118" editable="false" borderVisible="false" color="#CC3333"/>
    </mx:FormItem>
    <mx:Label x="16" y="325" text="Search" fontWeight="bold" color="#CC3333" fontSize="22"/>
    <mx:FormItem label="Justification/Notes:" x="294" y="586">
        <mx:TextArea id="txtNote"  width="292" height="85"/>
    </mx:FormItem>
    <mx:FormItem label="Decal#:" x="571" y="477" width="121">
        <mx:TextInput id="txtDecNo" width="65" maxChars="5"/>
    </mx:FormItem>
    <mx:FormItem label="Category" x="489" y="507">
        <mx:ComboBox id="cmbCategory"
                     prompt="Select Decal Category"
                     selectedIndex="-1">
            <mx:dataProvider>
                <mx:Object label="White" data="WHIT" />
            </mx:dataProvider>
        </mx:ComboBox>

    </mx:FormItem>
    <mx:FormItem label="Payment Type" x="445" y="535">
        <mx:ComboBox id="cmbPayment"
                     prompt="Select Payment Type"
                     selectedIndex="-1" width="160">
            <mx:dataProvider>
                <mx:Object label="Payment Upon Request" data="A" />
                <mx:Object label="Tag or 25yrs service FREE" data="T" />
            </mx:dataProvider>
        </mx:ComboBox>
    </mx:FormItem>
    <mx:FormItem id="lblAdditional" color="#2FAB5E" x="525" y="561">
        <mx:CheckBox label="$1.00 Additional" fontStyle="italic" color="#2F3F81" id="chkAdditional" click="chkAdditional_clickHandler(event)"/>
    </mx:FormItem>
    <mx:FormItem label="" id="lblVoidValue" color="#D21703" fontSize="13" fontFamily="Verdana" fontWeight="bold" fontStyle="normal" x="410" y="687">
        <mx:CheckBox label="Void" id="chkVoid" click="chkVoid_clickHandler(event)" color="#2F3F81" fontSize="10" fontFamily="Arial" fontStyle="italic"/>
    </mx:FormItem>
    <mx:FormItem label="Order Date:" x="509" y="415" width="62">
    </mx:FormItem>
    <mx:FormItem label="Pick-up Date:" x="501" y="448" width="72">
    </mx:FormItem>
    <mx:FormItem label="Dec Year:" x="310" y="448" fontStyle="italic">
        <mx:TextInput id="txtDecalYear" width="79" borderVisible="false" color="#CC3333"/>
    </mx:FormItem>
    <mx:FormItem label="Guest Name" x="460" y="371">
        <mx:TextInput id="txtStudentName" width="152" maxChars="100"/>
    </mx:FormItem>
    <mx:Button label="Save" width="156" id="btnSave" click="btnSave_clickHandler(event)" x="539" y="685"/>
    <mx:FormItem label="Decal Type:" x="458" y="477" width="103">
        <mx:TextInput id="txtDecalType" width="26"/>
    </mx:FormItem>
    <mx:Label x="297" y="324" text="Decal Info" fontWeight="bold" color="#CC3333" fontSize="22"/>
    <mx:TextInput x="571" y="413" width="119" id="txtOriginalDate" maxChars="50"/>
    <mx:TextInput x="571" y="446" width="119" id="txtUpdateDate" maxChars="50"/>
    <mx:Button x="850" y="17" label="Return to Decal Dispatch" width="173" click="button4_clickHandler(event)"/>

</mx:Application>

2 个答案:

答案 0 :(得分:3)

更改此行:

var itemName:String = (item.DECALNUMPERM as String);

return item.DECALNUMPERM&amp;&amp; item.DECALNUMPERM.toString()。indexOf(searchString)&gt; -1;

item.DECALNUMPERM是一个数字,将其转换为String将导致为空。


BTW:除此之外,我会把这个文件分成几个。 500行文件通常不是调试的好主意。

你有没有理由使用Flex 3而不是Flex 4?


修改此外,有时item.DECALNUMPERM为空。因此,您需要检查null以及执行toString()。请尝试使用此行:

return item.DECALNUMPERM && item.DECALNUMPERM.toString().indexOf(searchString) > -1;

您还需要在其他地方进行更改,例如:

private function filterTagMyArrayCollection(item:Object):Boolean {
var searchString:String = searchTag.text.toLowerCase();
var itemName:String = (item.VTAG as String).toLowerCase();
return itemName.indexOf(searchString) > -1;
}

private function filterDLMyArrayCollection(item:Object):Boolean {
var searchString:String = searchDL.text;
var itemName:String = (item.DLNUM as String);
return itemName.indexOf(searchString) > -1;
}

答案 1 :(得分:1)

亲爱的,读完这个很痛苦。你应该真的尝试清理。

正如错误所说,导致问题的功能是:

private function filterDecalMyArrayCollection(item:Object):Boolean {
   var searchString:String = searchDecal.text;
   var itemName:String = (item.DECALNUMPERM as String);
   return itemName.indexOf(searchString) > -1;
}

当DECALNUMPERM属性为null时,可能会失败,因为提到的错误。你有没有试过调试这个?