473,799 Members | 3,148 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

7 New Member
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.EventArg s e)
{
int ParamID=Convert .ToInt16(Sessio n["ParamID"].ToString());(s howing exception at this line)
....
....
}
private void grdParameters_I temCommand(obje ct source, System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
{
Session["ParamID"]=e.Item.Cells[0].Text.ToString( );
.....
.....
....
}

The exception that is raised is:
"Null pointer Exception unhandled by the usercode".Objec t reference not set to an instance of an object.
Nov 10 '08 #1
6 3857
r035198x
13,262 MVP
Which line is reported for the error? You do understand what the exception means, right?
Nov 10 '08 #2
kenobewan
4,871 Recognized Expert Specialist
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
swathi amireddy
7 New Member
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 MVP
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 New Member
int ParamID=0;//Initialize with default value
if (Session["ParamID"] != null)
{
ParamID=Convert .ToInt16(Sessio n["ParamID"]);
}

hope this will helps you..
Nov 10 '08 #6
swathi amireddy
7 New Member
int ParamID=0;//Initialize with default value
if (Session["ParamID"] != null)
{
ParamID=Convert .ToInt16(Sessio n["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
20375
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 , for example, when the file doesnt exists, i should not return any reference to a bad constructed object, so i need something as a NULL reference object. I suppose i could return a pointer instead, but i have some code written with references which...
5
24730
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 s); public void Deserialize(Stream s); Within the MyUserControl class, there is a field of type MyInnerClass
5
2182
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
2083
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 pass a null value to a class constructor whch has a object paramer can be 0? In general, how C# handle a pointer with value 0;
2
1552
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. 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.
7
1620
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 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. ...
3
2071
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: System.NullReferenceException: Object reference not set to an instance of an object
11
3269
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 my object is destroyed, I want my object to un-register this event. If I don't then the object would never be destroyed until the object I passed in the constructor is destroyed. I have implemented a Dispose(), Dispose(bool), and ~Finalize...
76
4721
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 pointers are allowed to be null, while references must refer an existing variable of required type. The null is normally used for making optional parameters. But there is no way to pass null reference in C#. Something is missing.
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10490
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10259
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5589
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4145
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.