1

当我尝试运行我的代码时出现以下错误。

TypeError:错误#1010:术语未定义且没有属性。

    private function calculateFIX001Value(custfields:Array):Number
    {
        var result:Number = new Number;
        var valueObj:Object;

        try{
                var markUp:Number = 0.01;
                var projectValue:String = "";
                var marketCategory:String = "";

                for each (var custField:Object in custfields)
                {
                    if (custField.fieldLabel == 'Segment Category')
                        marketCategory = custField.selectedValue[0];

                    if (custField.fieldLabel == 'Project Value (R)')
                        projectValue = custField.selectedValue[0].toString().replace("R","");
                        projectValue = projectValue.replace(",","");
                        projectValue = projectValue.replace(",","");
                        projectValue = projectValue.replace(",","");
                }

                switch (marketCategory)
                {
                    case "23": //5% Markup for Building
                        markUp = new Number(5 / 100);
                        break;
                    case "24": //11% Markup for Civils
                        markUp = new Number(11 / 100);
                        break;
                    case "25": //2% Markup for Scaffolding
                        markUp = new Number(2 / 100);
                        break;
                    default:
                        break;
                }

                if ((projectValue != "" && projectValue != '0') && marketCategory != "")
                {
                    var revenue:Number = new Number;
                    //if (!_model.myProfile.switchOpportunityInMillions)
                    //  revenue = parseFloat(projectValue) * 1000000 * markUp;
                    //else
                        revenue = parseFloat(projectValue) * markUp;
                    valueObj = new Object;
                    valueObj.label = "Expected Revenue";
                    valueObj.value = revenue;
                    //result.push(valueObj);
                    result = revenue;
                    //rm.saveOpportunityValue(_currentOpportunity.id, revenue);
                }
                else
                {
                    var errorObj:Object = new Object;
                    var errMsg:String = "";

                    if (projectValue == '' || projectValue == '0')
                        errMsg = "Project value not specified";

                    if (marketCategory == "")
                    {
                        if (errMsg != "")
                            errMsg += " or no Segment Category has been selected";
                        else
                            errMsg = "No Segment Category has been selected";
                    }
                    errorObj.label = 'Cannot calculate value.';
                    errorObj.value = errMsg + '.';
                    //result.push(errorObj);

                    result = 0;
                }
        } catch(e:Error) {
            Alert.show(e.toString());
        }

        return result;
    }
4

2 回答 2

2

TypeError: Error #1010 也称为“空指针异常”,这意味着您试图访问空对象属性。

如果您查看堆栈跟踪告诉您的行,您可能会发现原因没有太大问题。

于 2012-10-02T13:39:54.317 回答
0

这是帮助您解决问题的间接答案:(因为您的代码中有很多东西可能为空或未定义并导致此错误)

你几乎所有的代码都在 a 中try/catch,所以你的错误实际上并没有被抛出,你只是在追踪被捕获的错误。

抛出错误(通过删除 try/catch 或在 catch 块中手动抛出):

catch(e:Error) {
    Alert.show(e.toString()); //instead of this, for debugging, do the line below:
    Throw e; //this will throw the error, so you will get your stack trace and the line number of error
}

要获取错误的行号并查看堆栈跟踪,您需要在调试播放器或您的 IDE(例如 Flash 或 FlashBuilder)中运行。

于 2012-10-02T16:39:04.567 回答