nullreference
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: nullreference

  1. #1
    Join Date
    Jul 2009
    Posts
    2

    nullreference

    i cant find the why im getting this error, can someone point it out please??

    I get this:

    An unhandled exception of type 'System.NullReferenceException' occurred in WindowsFormsApplication2.exe

    in this part of the code:

    Code:
    vehicleData.Rows.Add(vehicle.TypeDisplayName.ToCharArray(),vehicle.DefaultDriverId,vehicle.VehicleId,vehicle.OwnerId,
                                vehicle.DisplayName.ToCharArray(), vehicle.Description.ToCharArray(), vehicle.Registration.ToCharArray(), vehicle.Notes.ToCharArray(),
                                vehicle.VehicleTypeId, vehicle.VehicleProfileId,vehicle.NotifyDriverOfGeofenceAlert,vehicle.IsProfile,vehicle.VehicleGroupId,
                                vehicle.CreatedDateTime, vehicle.ModifiedDateTime, vehicle.UserId, vehicle.UniqueVehicleID.ToCharArray(),
                                vehicle.DefaultVehicleStateID, vehicle.GISCulture.ToCharArray());

    THX

    Code:
    private void gruposBtn_Click(object sender, EventArgs e)
            {
                var owner_response = proxy.GetOwners();
    
                if(owner_response != null)
                {
                    DataTable vehicleData = new DataTable();
                    foreach(var owner in owner_response.Owners)
                    {
                        var message_response = proxy.GetGroups(owner.OwnerId);
                        var vehicle_response = proxy.GetVehicles(owner.OwnerId);
                        
                        vehicleData.Columns.Add("TypeDisplayName", typeof(SqlString));
                        vehicleData.Columns.Add("DefaultDriverId", typeof(Guid));
                        vehicleData.Columns.Add("VehicleId", typeof(Guid));
                        vehicleData.Columns.Add("OwnerId", typeof(Guid));
                        vehicleData.Columns.Add("DisplayName", typeof(SqlString));
                        vehicleData.Columns.Add("Description", typeof(SqlString));
                        vehicleData.Columns.Add("Registration", typeof(SqlString));
                        vehicleData.Columns.Add("Notes", typeof(SqlString));
                        vehicleData.Columns.Add("VehicleTypeId", typeof(Guid));
                        vehicleData.Columns.Add("VehicleProfileId", typeof(Guid));
                        vehicleData.Columns.Add("NotifyDriverOfGeofenceAlert", typeof(Boolean));
                        vehicleData.Columns.Add("IsProfile", typeof(Boolean));
                        vehicleData.Columns.Add("VehicleGroupId", typeof(Guid));
                        vehicleData.Columns.Add("CreatedDateTime", typeof(DateTime));
                        vehicleData.Columns.Add("ModifiedDateTime", typeof(DateTime));
                        vehicleData.Columns.Add("UserId", typeof(Guid));
                        vehicleData.Columns.Add("UniqueVehicleId", typeof(SqlString));
                        vehicleData.Columns.Add("DefaultVechileStateId", typeof(Boolean));
                        vehicleData.Columns.Add("GISCulture", typeof(SqlString));
    
                        foreach(var vehicle in vehicle_response.Vehicles)
                        {
                            vehicleData.Rows.Add(vehicle.TypeDisplayName.ToCharArray(),vehicle.DefaultDriverId,vehicle.VehicleId,vehicle.OwnerId,
                                vehicle.DisplayName.ToCharArray(), vehicle.Description.ToCharArray(), vehicle.Registration.ToCharArray(), vehicle.Notes.ToCharArray(),
                                vehicle.VehicleTypeId, vehicle.VehicleProfileId,vehicle.NotifyDriverOfGeofenceAlert,vehicle.IsProfile,vehicle.VehicleGroupId,
                                vehicle.CreatedDateTime, vehicle.ModifiedDateTime, vehicle.UserId, vehicle.UniqueVehicleID.ToCharArray(),
                                vehicle.DefaultVehicleStateID, vehicle.GISCulture.ToCharArray());
                        }
                        string nombre = owner.OwnerName;
                    }

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,441

    Re: nullreference

    You have to step through your code to find out what is null.

    For example, the following would give you a null exception if the DisplayName property is null:
    Code:
    vehicle.DisplayName.ToCharArray():

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center