2013-04-30 138 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未設置。

相關問題