|
-
February 19th, 2006, 08:39 PM
#1
Object reference not set to an instance of an object
I have the following code in a code behind file:
----------------------------DisplayList.aspx.vb------------------------------------------
Public Class DisplayListCodeBehind
Inherits System.Web.UI.Page
Protected WithEvents pageSectionAdd As System.Web.UI.WebControls.Button
Protected WithEvents pageSectionRemove As System.Web.UI.WebControls.Button
Protected WithEvents pageSectionOptions As System.Web.UI.WebControls.ListBox
Protected WithEvents pageSectionCurrent As System.Web.UI.WebControls.ListBox
public Sub setSessions
pageSectionOptions.items.clear
pageSectionCurrent.Items.clear
if NOT Session("sectionA") = "false" then
...........
...........
...........
End Sub
End Class
------------------------------------------------------------------------------------------
Within my main page file, i have the following code:
--------------------------page.aspx-----------------------------------------------------
...........
...........
...........
<td>
<asp:ListBox runat="server" SelectionMode="Single" id="pageSectionOptions">
</asp:ListBox>
</td>
<td>
<asp:Button id="pageSectionAdd" width="100" text=">>Add>>" runat="server" />
<br />
<asp:Button id="pageSectionRemove" width="100" text="<<Remove<<" runat="server" />
</td>
<td>
<asp:ListBox runat="server" width="200" SelectionMode="Single" id="pageSectionCurrent">
</asp:ListBox>
</td>
...........
...........
...........
...........
-------------------------------------------------------------------------------------------
But i'm getting the following error, can anyone explain why???
----------------------------------------error----------------------------------
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:
Line 22:
Line 23: public Sub setSessions
Line 24: pageSectionOptions.items.clear
Line 25: pageSectionCurrent.Items.clear
Line 26:
Source File: \\genfs2\www40\joshgosselin\CodeBehind\SubDisplayList.aspx.vb Line: 24
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
DisplayListCodeBehind.setSessions() in \\genfs2\www40\joshgosselin\CodeBehind\SubDisplayList.aspx.vb:24
DisplayListCodeBehind.Page_Load(Object sender, EventArgs e) in \\genfs2\www40\joshgosselin\CodeBehind\SubDisplayList.aspx.vb:18
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750
-----------------------------------------------------------------------------------------
Many Thanks in advance
Josh
-
February 19th, 2006, 08:41 PM
#2
Re: Object reference not set to an instance of an object
You can't rely on a Session variable staying in memory. You need to check first if the variable is null - if so, reload it / etc.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|