AnsweredAssumed Answered

nullreferenceexception was unhandled by user code

Question asked by hamad2 on Nov 17, 2012
Latest reply on Nov 27, 2012 by hamad2
I am developing an extension similar to American community Survey Mapping, I am trying to populate Combo box with TOC layers, or by using open command in my form, but I am getting  nullreferenceexception was unhandled by user code error  near:

Dim num2 As Integer = (strArray.Length - 1)

Also I am getting many warning messages  like  "Variable 'variableName' is passed by reference before it has been assigned a value. A null reference exception could result at runtime".

Here is part of the code where I get the error.

Private Sub CmdOpenFeture_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdOpenFeture.Click         Dim obj2 As IEnumGxObject         Dim dialog As IGxDialog = New GxDialogClass         Dim filters As IGxObjectFilterCollection = DirectCast(dialog, IGxObjectFilterCollection)         Dim filter5 As IGxObjectFilter = New GxFilterTablesAndFeatureClassesClass         Dim filter As IGxObjectFilter = New GxFilterPersonalGeodatabasesClass         Dim filter2 As IGxObjectFilter = New GxFilterPGDBFeatureClassesClass         Dim filter3 As IGxObjectFilter = New GxFilterPGDBFeatureDatasetsClass         Dim filter4 As IGxObjectFilter = New GxFilterPGDBTablesClass         filters.AddFilter(filter5, True)         filters.AddFilter(filter, False)         filters.AddFilter(filter3, False)         filters.AddFilter(filter4, False)         Dim dialog2 As IGxDialog = dialog         dialog2.AllowMultiSelect = False         dialog2.ButtonCaption = "Select"         dialog2.Title = "Select Input File"         Dim flag As Boolean = dialog2.DoModalOpen(0, obj2)         dialog2 = Nothing         If flag Then             Dim strArray As String()             Dim fullName As String = obj2.Next.FullName             CboOpenfeature.Text = fullName             InputDataCmd.readFieldFromFeature(fullName, (strArray))             CboFeaturefield.Items.Clear()             Dim num2 As Integer = (strArray.Length - 1)             Dim i As Integer = 0             Do While (i <= num2)                 CboFeaturefield.Items.Add(strArray(i))                 i += 1             Loop             TxtOutputPath.Text = (InputDataCmd.featureWorkspacePath & "\" & InputDataCmd.featureName & "_joined.shp")         End If      End Sub

I do appreciate your help
Thank you