Question

. pls help me ... if i debug below code then it is showing Cannot access a property or method of a null object reference ..how to solve it

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;
        }
    }
Was it helpful?

Solution

One of the variables you are trying to read from or write to is Null, i.e. has no value yet. The line number in your error message should tell you where this occurs.

You can avoid this by using for instance:

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

My guess is that this stems from upload.selectedValue - are you sure this is set? You can try replacing the first part of your code with the following:

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

If that removes the error, you just have to figure out why upload.selectedValue is not set.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top