Solved

I Need help with error handling

Posted on 2011-09-07
5
181 Views
Last Modified: 2012-05-12
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?
0
Comment
Question by:mainrotor
5 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 36498965
You haven't initialized a variable. Read #1 in my article.
0
 
LVL 2

Expert Comment

by:nafigueiredo
ID: 36499403
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
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 36500340
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
 
LVL 15

Expert Comment

by:navneethegde
ID: 36500802
Hi!

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

Thanks!
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 36502266
Your object is not Static
A static object can still be uninitialized  : )
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now