Encounter NullReferenceException when using EditGeometry

315
1
09-29-2013 07:00 PM
Labels (1)
StanleyHo
New Contributor III
Hi,

I have encounter NullReferenceException when using EditGeometry and have no idea how to solve it.

These are my controls:
Map (World_Street_Map) - 1 (call MyMap)
Graphics layers - 3 (call it glA, glB)
EditGeometry - 1 (call EditGeometry)
Handler - 2 (gl_MouseLeftButtonDown, EditGeometry_GeometryEdit, MyMap_MouseLeftButtonDown)

Steps:
1) create 2 polygons (call poly1 and poly2) on glA (different location)
2) create a line from middle of each polygon to some location on glB (both polygon links to different location)
3) select poly1
4) select poly2 (without unselecting poly1 first)
5) encounter exception

Each handler content:
1) MyMap_MouseLeftButtonDown -
EditGeometry.StopEdit() if any polygon is selected.

2) gl_MouseLeftButtonDown -
EditGeometry.StopEdit() //clear any selected polygon and update its information (updating is done in EditGeometry_GeometryEdit handler)
//Search Associated line in glB and overwrite it with a polyline with transparent color.
EditGeometry.StartEdit(e.Graphic);

3) EditGeometry_GeometryEdit -
if (e.Action == EditGeometry.Action.EditStarted)
{
    //get midpoint of selected polygon
}
else if (e.Action == EditGeometry.Action.EditCompleted)
{
    //compute moved value x, y
    //compute rotated angle
    glA.ClearGraphics();
    //redraw all polygon in the new position and rotated angle
    glB.ClearGraphics();
    //redraw all line from mid of poly to the specific location (same location as the initial state)
}


StackTrace -
System.NullReferenceException was unhandled
  HResult=-2147467261
  Message=Object reference not set to an instance of an object.
  Source=ESRI.ArcGIS.Client
  StackTrace:
       at ESRI.ArcGIS.Client.EditGeometry.SetEditGraphic(Graphic graphicToEdit)
       at ESRI.ArcGIS.Client.EditGeometry.StartEdit(Graphic graphicToEdit)
       at Mcs.Gui.XsisMissionPlanning.XsisMissionPlanningGui.GraphicsLayer_MouseLeftButtonDown(Object sender, GraphicMouseButtonEventArgs e) in c:\Projects\Testing\Test\Src\Test.xaml.cs:line 205
       at ESRI.ArcGIS.Client.GraphicsLayer.element_MouseLeftButtonDown(Object sender, MouseButtonEventArgs e)
       at ESRI.ArcGIS.Client.Symbols.GraphicElement.OnMouseLeftButtonDown(MouseButtonEventArgs e)
       at System.Windows.UIElement.OnMouseLeftButtonDownThunk(Object sender, MouseButtonEventArgs e)
       at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
       at System.Windows.UIElement.OnMouseDownThunk(Object sender, MouseButtonEventArgs e)
       at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
       at System.Windows.Input.InputManager.ProcessStagingArea()
       at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
       at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
       at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
       at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.Run()
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run(Window window)
       at System.Windows.Application.Run()
       at XsisMissionPlanningGui.App.Main() in c:\Projects\Test\Test\obj\Debug\Src\App.g.cs:line 0
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:


Note:
1) Deselect 1 polygon first before selecting the next will not cause the exception.

Please help. Thanks
0 Kudos
1 Reply
DavidLednik
Occasional Contributor II
Which version of wpf is this?

If I understand correctly glA and glB are referring to graphics layers A and B?

David
0 Kudos