Mohamed Aldawi Mohamed Aldawi - 2 months ago 6
Vb.net Question

An unhandled exception of type 'System.NullReferenceException' occured in VB.NET

Private Sub btnFeedItem_Click(sender As Object, e As EventArgs) Handles btnFeedItem.Click

If nResult = 0 Then
Dim vItem As SAPbobsCOM.Items
Dim RetVal As Long

vItem = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems)
'Set value to mandatory fields:
vItem.ItemCode = txtItemCode.Text
'Set Value to other fields
vItem.ItemName = txtItemName.Text

'Adding the Item
RetVal = vItem.Add

'Result Text
If RetVal = 0 Then
MsgBox("The Items :" + " " + txtItemCode.Text + "Created Smoothly")
Else
MsgBox("Please Check :" + " " + oCompany.GetLastErrorDescription())
End If
End I**strong text**f


After running this code the following error is appeared :


An unhandled exception of type 'System.NullReferenceException


For this line:

vItem = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems)


Can anyone help me find the solution for this error ?

Answer

Make sure that following thing

oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems)

Returns object of following type

SAPbobsCOM.Items

Everything else seems good.

Comments