TypeError: Error #1009: 无法访问空对象引用的属性或方法。

本文详细解析了一次在使用Flex框架过程中遇到的TypeError错误,问题源于尝试访问空对象引用的属性或方法。通过分析错误堆栈,我们找到了问题的根源在于模块实例化方式不当。文章提供了正确的实例化方法,并解释了Flex框架中Application和子模块实例化的区别,帮助开发者避免类似问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天项目中碰到这个问题,纠结了我一整天时间,终于明白了问题的所在。
报错信息:
TypeError: Error #1009: 无法访问空对象引用的属性或方法。
at mx.core::UIComponent/getStyle()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:10372]
at mx.core::UIComponent/getConstraintValue()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8612]
at mx.core::UIComponent/get horizontalCenter()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8730]
at spark.layouts::BasicLayout/measure()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\layouts\BasicLayout.as:215]
at spark.components.supportClasses::GroupBase/measure()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\components\supportClasses\GroupBase.as:1078]
at mx.core::UIComponent/measureSizes()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8042]
at mx.core::UIComponent/validateSize()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:7966]
at spark.components::Group/validateSize()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\components\Group.as:873]
at mx.managers:ayoutManager/validateSize()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:617]
at mx.managers:ayoutManager/doPhasedInstantiation()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:709]
at mx.managers:ayoutManager/doPhasedInstantiationCallback()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1072]
看了差不多半天也看不出个名堂。
网上查了以后,发现flex中只有Application可以通过var a:Application; 这样定义一个实例并传递给其他模块,但是模块这样是不可以的。网上说模块这样可以,var a = XXModuleLoader.child as XXModule; 你可以试一试。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值