473,406 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Null Pointer Exception,Object reference not set to an instance of an object

Currently im trying to migrate a project from .net 1.1 to 2.0.While running the application its giving an exception for the below code while doing the update operation:

protected void btnUpdate_Click(object sender, System.EventArgs e)
{
int ParamID=Convert.ToInt16(Session["ParamID"].ToString());(showing exception at this line)
....
....
}
private void grdParameters_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Session["ParamID"]=e.Item.Cells[0].Text.ToString();
.....
.....
....
}

The exception that is raised is:
"Null pointer Exception unhandled by the usercode".Object reference not set to an instance of an object.
Nov 10 '08 #1
6 3824
r035198x
13,262 8TB
Which line is reported for the error? You do understand what the exception means, right?
Nov 10 '08 #2
kenobewan
4,871 Expert 4TB
I suggest place the session string in a variable and write to check it exists. You want to think about adding some logic should the session variable be empty.
Nov 10 '08 #3
I suggest place the session string in a variable and write to check it exists. You want to think about adding some logic should the session variable be empty.
By debugging,we came to know that its getting the NULL value.Can u suggest some code that we need to add to solve the issue??
Nov 10 '08 #4
r035198x
13,262 8TB
Correcting it is as easy as putting a test (if test) for null before dereferencing (.dotting) the value that is null.
Nov 10 '08 #5
Murugs
18
int ParamID=0;//Initialize with default value
if (Session["ParamID"] != null)
{
ParamID=Convert.ToInt16(Session["ParamID"]);
}

hope this will helps you..
Nov 10 '08 #6
int ParamID=0;//Initialize with default value
if (Session["ParamID"] != null)
{
ParamID=Convert.ToInt16(Session["ParamID"]);
}

hope this will helps you..

Thank you....
its working....
Nov 11 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Pablo J Royo | last post by:
Hello: i have a function that reads a file as an argument and returns a reference to an object that contains some information obtained from the file: FData &ReadFile(string FilePath); But ,...
5
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
5
by: Boniek | last post by:
Hi I define a public property in a new form and I can see this property in table of Properties in Visual. How I can hide this property to see only in code ? Thank's Boniek
2
by: Fei Li | last post by:
Hi, Is null value for a class instance allowed in C#? for example: MyClass obj = null; If Not, how to initiate an instance with value 0? How to detect if an instance is "newed" ? And how to...
2
by: I am Sam | last post by:
I keep getting the following exception error: Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request....
7
by: wrytat | last post by:
How do I check if an object is null in vb? I tried using IsDBNull but it doesn't work at all. It gives me this error when I try statement like If Not IsDBNull(theStock.WIPQty) Then: Object...
3
by: Ganesh Palaniappan | last post by:
We're getting following exception for the below piece of code. We're wondering how it is possible since we're having a null check for objGraphics and strokePen... Exception:...
11
by: MikeT | last post by:
This may sound very elementary, but can you trap when your object is set to null within the object? I have created a class that registers an event from an object passed in the constructor. When...
76
by: valentin tihomirov | last post by:
As explained in "Using pointers vs. references" http://groups.google.ee/group/borland.public.delphi.objectpascal/browse_thread/thread/683c30f161fc1e9c/ab294c7b02e8faca#ab294c7b02e8faca , the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.