2013-04-30 141 views
-2

。请帮帮我......如果我调试下面的代码则显示无法访问空对象引用的属性或方法..how解决它无法访问空对象引用的属性或方法:as3

protected function upload_itemClickHandler(event:ItemClickEvent):void 
    { 
     if(upload.selectedValue == "allupload") 
     { 
     theModel.removeAllViews(); 
     //ModuleLbl.text = headerText; 
     theModel.uploadStatusMessage = ""; 
     theModel.adminStatusMessage = ""; 
     var gallComp:ManageGallery = new ManageGallery(); 
     gallComp.theModel = theModel; 
     theModel.AdminUIComponent.addChild(gallComp as DisplayObject); 
     theModel.adminObj["theTaskName"] = "GalleryRepository"; 
     theModel.adminObj["userID"] = theModel.activeUserObj.UserID; 
     theModel.adminObj["isAdminLogin"] = theModel.isAdminLogin; 
     theModel.theAdminEvt.dispatch(); 
     theModel.tempAdminParams = theModel.adminObj; 
     } 
    } 

回答

0

一个你想读的变量从或写入到Null,即没有价值。错误信息中的行号应该告诉你发生了什么。

您可以通过使用例如避免这种情况:

if(yourVariable != null){ 
    // do something with the variable 
} 

我的猜测是,这源于upload.selectedValue - 你确定这是设置?你可以尝试用下面的更换你的代码的第一部分:

if(!string.IsNullOrEmpty(upload.selectedValue) 
    && (upload.selectedValue == "allupload")) 
{ 
    // do stuff with theModel 
} 

如果删除错误,你就必须弄清楚为什么upload.selectedValue未设置。

相关问题