I Need help with error handling

I get the following error in my C#.Net app

Object reference not set to an instance of an object

How can I handle this?
mainrotorAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Jacques Bourgeois (James Burger)Connect With a Mentor PresidentCommented:
You need to call new on your variable before you can use it. Not knowing what type of object you use, I cannot give you a precise example, but here is how it would look for a form:
Form1 frm;
// And somewhere before using the form:
frm = new Form1 ( );

Open in new window

Or if you prefer:
Form1 frm = new Form1 ( );
// Use it when you want

Open in new window

0
 
käµfm³d 👽Commented:
You haven't initialized a variable. Read #1 in my article.
0
 
nafigueiredoCommented:
Hi

You have to check if your object is null before doing anything with it.

Like:

  if (myobject == null){
. .. do something
} else {
 do what you're supposed to do
}
0
 
NavneetSoftware EngineerCommented:
Hi!

Your object is not Static and Needs Initialization before using it.
Also read this
http://www.csharp411.com/c-object-initialization/

Thanks!
0
 
käµfm³d 👽Commented:
Your object is not Static
A static object can still be uninitialized  : )
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.