简体   繁体   English

无法访问空对象引用Flex的属性或方法

[英]Cannot access a property or method of a null object reference Flex

I've been trying to learn flex/flash programming and am working on a project where I need to populate a spinner list in flex dynamically from a string. 我一直在努力学习flex / flash编程,我正在开发一个项目,我需要在一个字符串中动态填充flex中的微调器列表。 I have a function that separates the string using "split" and now I need to populate an array list. 我有一个使用“split”分隔字符串的函数,现在我需要填充一个数组列表。 I have been working with this stupid big for hours now and can;t find help anywhere. 我已经和这个愚蠢的大人物一起工作了几个小时,可以在任何地方找到帮助。 I keep getting the following error: 我一直收到以下错误:

TypeError: Error #1009: Cannot access a property or method of a null object reference. TypeError:错误#1009:无法访问空对象引用的属性或方法。 at views::CommonPlaces/initApp()[/Users/twing207/Documents/Adobe Flash Builder 4.6/AmericanTaxi/src/views/CommonPlaces.mxml:30] at views :: CommonPlaces / initApp()[/ Users / twing207 / Documents / Adob​​e Flash Builder 4.6 / AmericanTaxi / src / views / CommonPlaces.mxml:30]

My code is here: 我的代码在这里:

<fx:Script>
    <![CDATA[
        import mx.collections.ArrayList;
        import spark.events.IndexChangeEvent;

        var Arr1:Array;
        var Arr2:Array;
        var Arr3:Array;

        [Bindable]
        public var CommonPlacesArray:ArrayList;

        var CommonPlacesData:String = new String("2133664:American Taxi Dispatch, Inc:Mount Prospect:834 E RAND RD|2133665:Walmart:Mount Prospect:930 Mount Prospect Plaza|2228885:Garage:Des Plaines:1141 Lee St|2228886:Asian Island:Palatine:1202 E Dundee Rd|2229464:Kohl's:Arlington Heights:700-856 W Dundee Rd|");
        var CurrentSelect:String = new String();

        private function initApp():void {

            Arr1 = CommonPlacesData.split("|");
            var arrLength:Number = new Number(Arr1.length);

            for (var i:Number = 0; i < (arrLength - 1); i++) {
                CurrentSelect = new String(Arr1[i]);
                Arr2 = CurrentSelect.split(":");

      //THE LINE BELOW IS WHERE IT STOPS:
                CommonPlacesArray.addItem(Arr2[1]);
            }

        }

It doesn't seem to like the "CommonPlacesArray.addItem" line. 它似乎不喜欢“CommonPlacesArray.addItem”行。 Any help or a point in the right direction would be great. 任何帮助或正确方向上的一点都会很棒。 Thanks in advanced! 提前致谢!

On another note, I am also getting the error: "Access of undefined property: data" on the following: 另外,我也收到错误:“访问未定义的属性:数据”,如下所示:

Here in another view I set the value for data.UserCommonReturnData to a string. 在另一个视图中,我将data.UserCommonReturnData的值设置为字符串。

function LoginLoaded (e:Event):void {
                        trace(e.target.data);
                        var ServerReturn:String;
                        ServerReturn = new String(e.target.data);
                        data.UserCommonReturnData = ServerReturn;
                        navigator.pushView(CommonPlaces, data);
                    }

and here I try to pull it back: 在这里我试着把它拉回来:

var CommonPlacesData:String = new String();
            var CurrentSelect:String = new String();

//The next line gives the error: CommonPlacesData = data.UserCommonReturnData; //下一行给出错误:CommonPlacesData = data.UserCommonReturnData;

Any idea?? 任何想法??

You never construct CommonPlacesArray, you just declare it. 你永远不会构造CommonPlacesArray,你只需要声明它。

var CommonPlacesArray:ArrayList = new ArrayList();

If you check the Array List API you can also clearly see it has a constructor that accepts an array, meaning you can copy the data to it without having to iterate over it yourself. 如果你检查Array List API,你也可以清楚地看到它有一个接受数组的构造函数,这意味着你可以将数据复制到它而不必自己迭代它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flex错误#1009:无法访问空对象引用的属性或方法 - Flex Error #1009: Cannot access a property or method of a null object reference Flex中的“无法访问空对象引用的属性或方法。”错误 - “Cannot access a property or method of a null object reference.” error in Flex 错误:无法在Flex中访问空对象引用的属性或方法 - Error: Cannot access a property or method of a null object reference in flex Flex 错误 #1009:无法访问 null object 引用的属性或方法 - Flex Error #1009: Cannot access a property or method of a null object reference 无法访问空对象引用的属性或方法 - Cannot access a property or method of a null object reference 如何解决TypeError:错误#1009:从Flex 3调用swf时无法访问空对象引用的属性或方法 - How to solve TypeError: Error #1009: Cannot access a property or method of a null object reference while calling swf from flex 3 AS3-错误#1009:无法访问空对象引用的属性或方法 - AS3 - Error #1009: Cannot access a property or method of a null object reference Actionscript3-无法访问空对象引用的属性或方法 - Actionscript3 - Cannot access a property or method of a null object reference AS3错误1009:无法访问空对象引用的属性或方法 - AS3 Error 1009 : Cannot access a property or method of a null object reference 动作3错误1009:无法访问空对象引用的属性或方法 - Actionscript 3 error 1009: Cannot access a property or method of a null object reference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM