I know that this question has been asked many times before, but I just can't work it out after reading all the responses. I have no clue what I'm doing wrong and looking at it for 2 days now. I have a nested class and just trying to assign values to it, but I keep getting this error. Debugging didn't bring me any further.
My class definitions:
Public Class DocumentHeader
Private _username As String
<JsonProperty("username")> _
Public Property username() As String
Get
Return _username
End Get
Set(ByVal value As String)
_username = value
End Set
End Property
Private _bus_act As String
<JsonProperty("bus-act")> _
Public Property bus_act() As String
Get
Return _bus_act
End Get
Set(ByVal value As String)
_bus_act = value
End Set
End Property
Private _ref_doc_no As String
<JsonProperty("ref-doc-no")> _
Public Property ref_doc_no() As String
Get
Return _ref_doc_no
End Get
Set(ByVal value As String)
_ref_doc_no = value
End Set
End Property
Private _header_txt As String
<JsonProperty("header-txt")> _
Public Property header_txt() As String
Get
Return _header_txt
End Get
Set(ByVal value As String)
_header_txt = value
End Set
End Property
Private _comp_code As String
<JsonProperty("comp-code")> _
Public Property comp_code() As String
Get
Return _comp_code
End Get
Set(ByVal value As String)
_comp_code = value
End Set
End Property
Private _pstng_date As String
<JsonProperty("pstng-date")> _
Public Property pstng_date() As String
Get
Return _pstng_date
End Get
Set(ByVal value As String)
_pstng_date = value
End Set
End Property
Private _trans_date As String
<JsonProperty("trans-date")> _
Public Property trans_date() As String
Get
Return _trans_date
End Get
Set(ByVal value As String)
_trans_date = value
End Set
End Property
Private _fis_period As String
<JsonProperty("fis-period")> _
Public Property fis_period() As String
Get
Return _fis_period
End Get
Set(ByVal value As String)
_fis_period = value
End Set
End Property
Private _doc_date As String
<JsonProperty("doc-date")> _
Public Property doc_date() As String
Get
Return _doc_date
End Get
Set(ByVal value As String)
_doc_date = value
End Set
End Property
Private _doc_type As String
<JsonProperty("doc-type")> _
Public Property doc_type() As String
Get
Return _doc_type
End Get
Set(ByVal value As String)
_doc_type = value
End Set
End Property
End Class
This is my main class:
Public Class RootObjectInvoice
Private _document_header As DocumentHeader
Public Property document_header() As DocumentHeader
Get
Return _document_header
End Get
Set(ByVal value As DocumentHeader)
_document_header = value
End Set
End Property
End Class
So far, so good, I think.
Now is my code:
Dim Root As RootObjectInvoice
Dim Document_Header As DocumentHeader
Root = New RootObjectInvoice
Document_Header = New DocumentHeader
Try
Document_Header = Root.document_header
Document_Header.bus_act = "AAAA"
At the line Document_Header.bus_act = "AAAA"
I get the NullpointerException
. I'm missing something here on how to initialize the object.
Any input would be appreciated.
As this works now, I have a problem with following (I'm used to C#, not VB) I added this property to the RootObjectInvoice
Private _metadata As List(Of Metadata)
Public Property metadata() As List(Of Metadata)
Get
Return _metadata
End Get
Set(ByVal value As List(Of Metadata))
_metadata = value
End Set
End Property
Then try to initialize it:
Dim Meta_Data() As List(Of Metadata)
Root.metadata() = New List(Of Metadata)
Meta_Data = Root.metadata
But the last line gives me the following error:
Value of type 'System.Collections.Generic.List(Of Metadata)' cannot be converted to '1-dimensional array of System.Collections.Generic.List(Of Metadata)'.