Connecting Tech Pros Worldwide Forums | Help | Site Map

Object reference not set to an instance of an object.

Newbie
 
Join Date: Mar 2008
Posts: 4
#1: Mar 26 '08
Hi,

I am new to VB .Net programming and is trying to create a webpage. I encountered the following error and is totally clueless on how to make it work:

==================ERROR=========================== =======
Object reference not set to an instance of an object.


Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
ICAPS_admin.WebForm1.Page_Load(Object sender, EventArgs e)
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()

================================================== =======

My webpage that I am trying to load is a very simple one which consist of only 3 dropdown list and 2 textbox. Below is my VB code:


==================Code ===================================
Expand|Select|Wrap|Line Numbers
  1. Public Class WebForm1
  2.     Inherits System.Web.UI.Page
  3.  
  4. #Region " Web Form Designer Generated Code "
  5.  
  6.     'This call is required by the Web Form Designer.
  7.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  8.  
  9.     End Sub
  10.     Protected WithEvents LabelSearchGemSecNo As System.Web.UI.WebControls.Label
  11.     Protected WithEvents txtBoxGemSecNo As System.Web.UI.WebControls.TextBox
  12.     Protected WithEvents LabelSearchUserID As System.Web.UI.WebControls.Label
  13.     Protected WithEvents txtBoxUserID As System.Web.UI.WebControls.TextBox
  14.     Protected WithEvents LabelStatus As System.Web.UI.WebControls.Label
  15.     Protected WithEvents LabelCAtype As System.Web.UI.WebControls.Label
  16.     Protected WithEvents LabelIndicator As System.Web.UI.WebControls.Label
  17.     Protected WithEvents ddlStatus As System.Web.UI.WebControls.DropDownList
  18.     Protected WithEvents ddlCAtype As System.Web.UI.WebControls.DropDownList
  19.     Protected WithEvents ddlIndicator As System.Web.UI.WebControls.DropDownList
  20.  
  21.     'NOTE: The following placeholder declaration is required by the Web Form Designer.
  22.     'Do not delete or move it.
  23.     Private designerPlaceholderDeclaration As System.Object
  24.  
  25.     Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
  26.         'CODEGEN: This method call is required by the Web Form Designer
  27.         'Do not modify it using the code editor.
  28.         InitializeComponent()
  29.     End Sub
  30.  
  31. #End Region
  32.  
  33.     Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  34.         'Put user code to initialize the page here
  35.     End Sub
  36.  
  37.  
  38.     Private Sub ddlCAtype_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlCAtype.SelectedIndexChanged
  39.  
  40.     End Sub
  41. End Class
  42.  
================================================== =======

Can anyone advise on this pls?

Thanks and regards,

livmacca

balabaster's Avatar
Moderator
 
Join Date: Mar 2007
Location: Canada
Posts: 757
#2: Mar 26 '08

re: Object reference not set to an instance of an object.


Put a breakpoint on the Page_Load event and run your web application. When the breakpoint is reached hit F11 to step through the application. What is the exact line of code executed when this error occurs?

I'm failing to see anything wrong with the code you provided - so if you've provided everything in your project, then I'm thinking that it's an environment problem. But I'd rather not tell you that your Visual Studio needs reinstalling - lord knows it takes long enough.
nev's Avatar
nev nev is offline
Familiar Sight
 
Join Date: Oct 2007
Posts: 251
#3: Mar 26 '08

re: Object reference not set to an instance of an object.


Check to see if anything being referenced is null or has valid data type.
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,161
#4: Mar 26 '08

re: Object reference not set to an instance of an object.


This is a VS2003 web application right? (In VS2005 you don't see the designer code like that)
Did you leave out any code? it looks like your page_load event is empty, but that's where it says the error is comming from?
Newbie
 
Join Date: Mar 2008
Posts: 4
#5: Mar 29 '08

re: Object reference not set to an instance of an object.


Quote:

Originally Posted by balabaster

Put a breakpoint on the Page_Load event and run your web application. When the breakpoint is reached hit F11 to step through the application. What is the exact line of code executed when this error occurs?

I'm failing to see anything wrong with the code you provided - so if you've provided everything in your project, then I'm thinking that it's an environment problem. But I'd rather not tell you that your Visual Studio needs reinstalling - lord knows it takes long enough.



Hi,

I guess it is the environment issue as it went away after i reinstalled VS 2003. Thanks for your reply! :)
Reply