Reflection code problem
-
Hi All, I have the following code which i have type for getting the use of refection for button class, But I got following error Object reference not set to an instance of an object.
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim pobjtype As Type pobjtype = Nothing Dim PobjObject As New Object PobjObject = Nothing Dim pobjButtons As New Windows.Forms.Button() PobjObject = pobjButtons.GetType() _**For Each PobjObject In pobjtype.GetMembers** //got error here_ LstDisplay.Items.Add(PobjObject.ToString()) Next End Sub End Class
Thanks in advance, amit -
Hi All, I have the following code which i have type for getting the use of refection for button class, But I got following error Object reference not set to an instance of an object.
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim pobjtype As Type pobjtype = Nothing Dim PobjObject As New Object PobjObject = Nothing Dim pobjButtons As New Windows.Forms.Button() PobjObject = pobjButtons.GetType() _**For Each PobjObject In pobjtype.GetMembers** //got error here_ LstDisplay.Items.Add(PobjObject.ToString()) Next End Sub End Class
Thanks in advance, amit -
You assign Nothing to the variable pobjtype, and then you try to use it as if it referenced an object. Did you assign the value to the wrong variable on the line before?
Despite everything, the person most likely to be fooling you next is yourself.
Sorry I didn't get you. Can you please explain with the line code ? Thanks
-
Sorry I didn't get you. Can you please explain with the line code ? Thanks
He means that you assign Nothing to variable: pobjtype = Nothing and then you try to use it for ... in pobjtype.GetMembers
Shay Noy