Follow in Twitter & Facebook



Like in Facebook

Powered By Blogger Widgets

Free Download

FREE Tools



Wednesday, May 2, 2012

Objectreference not set to an instance of an object.

Introduction:
Here we will discuss about one NullReferenceException Which i got while doing one Demo using Vb.Net. The exception was like "Objectreference not set to an instance of an object".

Description:
I got one EXception while doing one windows Application demo in Vb.Net.This Exception was nothing but one NullReferenceException. The Exception was like "Objectreference not set to an instance of an object".

At that time my code was like below:

Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, _
      ByVal e As System.ComponentModel.DoWorkEventArgs) _
      Handles BackgroundWorker1.DoWork
        ' Do some time-consuming work on this thread.
        System.Threading.Thread.Sleep(1000)
        ' Get argument.
        Dim args As ArgumentType = e.Argument
      
        ' Return value based on the argument.
        e.Result = args._a * args._b
    End Sub

So i was searching for the solution, Finally i used the new keyword to instanciate that one.
Insteadof Dim args As ArgumentType = e.Argument  ,i wrote  Dim args As ArgumentType = New ArgumentType().
Now my code looks like that as below:

 Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, _
      ByVal e As System.ComponentModel.DoWorkEventArgs) _
      Handles BackgroundWorker1.DoWork
        ' Do some time-consuming work on this thread.
        System.Threading.Thread.Sleep(1000)
        ' Get argument.
        Dim args As ArgumentType = New ArgumentType()
      
        ' Return value based on the argument.
        e.Result = args._a * args._b
    End Sub
so Now there is no error...

I am sharing the screenshot as below....


Also you can see some SQL Server and Asp.Net articles.




0 on: "Objectreference not set to an instance of an object."