Monday, March 26, 2012

Object reference not set to an instance of an object

Hello, I am trying to calculate a route out of two provided lat/long values (provided by a database, but for this example provided by entry).Something must be wrong with my array's because I get the error: Server Error in '/' Application.------------------------ Object reference not set to an instance of an object.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: Line 161: routeSegmentsSpec(0).Waypoint.Location = New LocationLine 162: routeSegmentsSpec(0).Waypoint.Location.LatLong = New LatLongLine 163: routeSegmentsSpec(0).Waypoint.Location.LatLong.Latitude = myWaypoints(0).LatitudeLine 164: routeSegmentsSpec(0).Waypoint.Location.LatLong.Longitude = myWaypoints(0).LongitudeLine 165: routeSegmentsSpec(0).Options = New SegmentOptions Source File: C:\Inetpub\wwwroot\MapPointSDK_RoutingVB\RoutePage.aspx.vb Line: 163 Stack Trace: [NullReferenceException: Object reference not set to an instance of an object.] RouteVB.RoutePage.buttonGetRoute_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\MapPointSDK_RoutingVB\RoutePage.aspx.vb:163 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102 The Code: Public Sub buttonGetRoute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonGetRoute.Click ' Create a global object to initialize MapPoint .NET objects. Dim [global] As RouteVB.[Global] = Context.ApplicationInstance ' Create a LatLong Object in the array hence, array of objects Dim latLongs(1) As LatLong latLongs(0) = New LatLong() ' 0 instance of LatLong class latLongs(0).Latitude = Convert.ToDouble(TextLatitudeA.Text) latLongs(0).Longitude = Convert.ToDouble(TextLongitudeA.Text) latLongs(1) = New LatLong() 'another instance of LatLong class latLongs(1).Latitude = Convert.ToDouble(TextLatitudeB.Text) latLongs(1).Longitude = Convert.ToDouble(TextLatitudeB.Text) ' Create the address object for the start point. Dim myAddressPointA As New MapPointService.Location latLongs(0).Latitude = TextLatitudeA.Text latLongs(0).Longitude = TextLongitudeA.Text 'Create the address object for the end point. Dim myAddressPointB As New MapPointService.Location latLongs(1).Latitude = TextLatitudeB.Text latLongs(1).Longitude = TextLongitudeB.Text ' Create a waypoint array to hold the two LatLong values. Dim myWaypoints(1) As LatLong myWaypoints(0) = myAddressPointA.LatLong myWaypoints(1) = myAddressPointB.LatLong ' Define the route segment specification. Dim routeSegmentsSpec(1) As SegmentSpecification ' Define the start segment. routeSegmentsSpec(0) = New SegmentSpecification routeSegmentsSpec(0).Waypoint = New Waypoint routeSegmentsSpec(0).Waypoint.Name = "Start" ' Define waypoint 1 (start point). routeSegmentsSpec(0).Waypoint.Location = New Location routeSegmentsSpec(0).Waypoint.Location.LatLong = New LatLong routeSegmentsSpec(0).Waypoint.Location.LatLong.Latitude =myWaypoints(0).Latitude routeSegmentsSpec(0).Waypoint.Location.LatLong.Longitude = myWaypoints(0).Longitude routeSegmentsSpec(0).Options = New SegmentOptions ' Enable the use of the PreferredRoads values as set in the driver profile. routeSegmentsSpec(0).Options.Preference = SegmentPreference.PreferredRoads ' Define the To segment. routeSegmentsSpec(1) = New SegmentSpecification routeSegmentsSpec(1).Waypoint = New Waypoint routeSegmentsSpec(1).Waypoint.Name = "End" ' Define waypoint 2 (end point). routeSegmentsSpec(1).Waypoint.Location = New Location routeSegmentsSpec(1).Waypoint.Location.LatLong = New LatLong routeSegmentsSpec(1).Waypoint.Location.LatLong.Latitude = myWaypoints(1).Latitude

routeSegmentsSpec(1).Waypoint.Location.LatLong.Longitude = myWaypoints(1).Longitude

hi can u please tell me in detail.

if possible send the code


solved

0 comments:

Post a Comment