Select to view content in your preferred language

Null Exception Error with Feature DataForm

861
2
Jump to solution
09-07-2012 10:09 AM
TanyaOwens
Frequent Contributor
I have a frustrating error that I can't figure out. Any help would be awesome.

I have a web application in API 2.4, SL 4 that renders different feature layers based on data in a certain field. From there the user makes a selection and enters their name and email and an email is sent. All this seems to be working fine but after the confirmation for the email I get a null exception error with the following info:

Microsoft JScript runtime error: Unhandled Error in Silverlight Application
Code: 4004   
Category: ManagedRuntimeError      
Message: System.NullReferenceException: Object reference not set to an instance of an object.
   at ESRI.ArcGIS.Client.Toolkit.FeatureDataForm.FieldControl_LostFocus(Object sender, RoutedEventArgs e)
   at MS.Internal.CoreInvokeHandler.InvokeEventHandler(UInt32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName, UInt32 flags)

I used http://www.silverlightnext.com/2010/06/send-email-from-silverlight-application.html to set up the email service. My Feature DataForm set up is as follows:

xaml:
 <Popup x:Name="MyPopup" VerticalOffset="25" HorizontalOffset="400" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Visibility="Visible">                  <Border BorderBrush="#FF51626F" BorderThickness="5">                     <StackPanel x:Name="PopUpPanel"                          Background="LightGray"                       Height="Auto"         Width="Auto" >                          <TextBlock  x:Name="PopUpText"         Height="40" Width="Auto"         Margin="15"         Text="THANK YOU VOLUNTEER!!"         FontFamily="Arial"          FontSize="30"         HorizontalAlignment="Center"          VerticalAlignment="Center"         Foreground="#FF51626F"/>                          <TextBlock  x:Name="PopUpSubText"         Margin="10"         Height="80" Width="Auto"         Text="You will be registered for the following location and time. Please complete the required contact information below and click SAVE. Please note, your NAME and an email address is required to complete your registration. You will receive an email confirming your volunteer location."         FontFamily="Arial"          FontSize="14"         HorizontalAlignment="Center"          VerticalAlignment="Center"         Foreground="#FF51626F" MaxWidth="400"          TextWrapping="Wrap" />                          <Border x:Name="FeatureDataFormBorder"          Visibility="Visible"          HorizontalAlignment="Center"          VerticalAlignment="Top"          Margin="10,10,10,0"          Width="400" Height="300" >                              <Border.Effect>                                 <DropShadowEffect Color="#FF51626F" Direction="-45" BlurRadius="20" Opacity=".75" />                             </Border.Effect>                              <esri:FeatureDataForm x:Name="MyFeatureDataForm"             FeatureLayer="{Binding Path=Layers[AllAvailableFeatureLayer], ElementName=Map}"           IsEnabled="True"                IsReadOnly="False"           LabelPosition="Left"          CommitButtonContent="Save"           EditEnded="MyFeatureDataForm_EditEnded"/>                         </Border>                          <StackPanel Margin="10" Orientation="Horizontal" HorizontalAlignment="Center">                             <Button x:Name="ClosePopupButton"            Height="34"            Width="73"            Content="Close"            Background="#FF51626F"            FontFamily="Verdana" FontSize="14"             Click="ClosePopupButton_Click" />                         </StackPanel>                      </StackPanel>                 </Border>             </Popup>


cs:
     private void FeatureLayer_MouseLeftButtonUp(object sender, GraphicMouseButtonEventArgs args)         {             foreach (Layer lyr in Map.Layers)             {                 if (lyr is FeatureLayer)                 {                     FeatureLayer featureLayer1 = lyr as FeatureLayer;                     for (int i = 0; i < featureLayer1.SelectionCount; i++)                         featureLayer1.SelectedGraphics.ToList().UnSelect();                 }             }               FeatureLayer featureLayer = sender as FeatureLayer;             SelectedFeatureLayer = featureLayer;              args.Graphic.Select();              MyFeatureDataForm.FeatureLayer = featureLayer;             MyFeatureDataForm.GraphicSource = args.Graphic;              FeatureDataFormBorder.Visibility = Visibility.Visible;             MyPopup.IsOpen = true;         }          private void FeatureLayer_BeginSaveEdits(object sender, ESRI.ArcGIS.Client.Tasks.BeginEditEventArgs e)         {          }          private void FeatureLayer_EndSaveEdits(object sender, ESRI.ArcGIS.Client.Tasks.EndEditEventArgs e)         {             foreach (Layer lyr in Map.Layers)             {                 if (lyr is FeatureLayer)                 {                     FeatureLayer featureLayer = lyr as FeatureLayer;                     featureLayer.Update();                 }             }                SendEmail();         }
0 Kudos
1 Solution

Accepted Solutions
TanyaOwens
Frequent Contributor
Aha!! With the help of a coworker - it is figured out. It seems like I needed to separate out the Feature update from the save edits:

        private void FeatureLayer_BeginSaveEdits(object sender, ESRI.ArcGIS.Client.Tasks.BeginEditEventArgs e)         {          }          private void FeatureLayer_EndSaveEdits(object sender, ESRI.ArcGIS.Client.Tasks.EndEditEventArgs e)         {             //foreach (Layer lyr in Map.Layers)             //{             //    if (lyr is FeatureLayer)             //    {             //        FeatureLayer featureLayer = lyr as FeatureLayer;             //        //featureLayer.Update();             //    }             //}              SendEmail();         }          private void refreshMap()         {             foreach (Layer lyr in Map.Layers)             {                 if (lyr is FeatureLayer)                 {                     FeatureLayer featureLayer = lyr as FeatureLayer;                     featureLayer.Update();                 }             }         }     private void ClosePopupButton_Click(object sender, RoutedEventArgs e)         {             refreshMap();             MyPopup.IsOpen = false;         }

View solution in original post

0 Kudos
2 Replies
TanyaOwens
Frequent Contributor
Update:

It appears that the featureLayer.Update(); is throwing the Null Exception error. This line was updating the feature layer so the map would display the correct color for the available time slot. Any advice on how to add this in but fix the null exception error it is causing?
0 Kudos
TanyaOwens
Frequent Contributor
Aha!! With the help of a coworker - it is figured out. It seems like I needed to separate out the Feature update from the save edits:

        private void FeatureLayer_BeginSaveEdits(object sender, ESRI.ArcGIS.Client.Tasks.BeginEditEventArgs e)         {          }          private void FeatureLayer_EndSaveEdits(object sender, ESRI.ArcGIS.Client.Tasks.EndEditEventArgs e)         {             //foreach (Layer lyr in Map.Layers)             //{             //    if (lyr is FeatureLayer)             //    {             //        FeatureLayer featureLayer = lyr as FeatureLayer;             //        //featureLayer.Update();             //    }             //}              SendEmail();         }          private void refreshMap()         {             foreach (Layer lyr in Map.Layers)             {                 if (lyr is FeatureLayer)                 {                     FeatureLayer featureLayer = lyr as FeatureLayer;                     featureLayer.Update();                 }             }         }     private void ClosePopupButton_Click(object sender, RoutedEventArgs e)         {             refreshMap();             MyPopup.IsOpen = false;         }
0 Kudos