Mohamed Aldawi Mohamed Aldawi - 1 year ago 146 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")
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 Source

Make sure that following thing


Returns object of following type


Everything else seems good.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download