Windows Develop Bookmark and Share   
 index > Windows Forms General > Null Reference Exception was unhandled: Object reference not set to an instance of an object.
 

Null Reference Exception was unhandled: Object reference not set to an instance of an object.

Hi,

I've an application to capture video of image as well as grab still image. It’s running well. Then, I put loop in the code so the application could keep capturing the image repeatedly and automatically. However it gives one exception error:

NullReferenceException was unhandled à ”Object reference not set to an instance of an object".

I found that, this error emerged when I called image from the folder. The reason of my assumption is because when I put comment notation before that line code, the application could run well.

These are the code that call image file from the folder outside of the main body of code programming.

//load an image for subtract

System.Drawing.Bitmap image2 = (Bitmap)Bitmap.FromFile("plane.Jpeg");

//// apply filter subtract===>>>> call file from out bin folder <<<<=====

System.Drawing.Bitmap subtract = filter1.Apply(image2);

However, when I run the code, the error refer to this code:

catch (Exception ex)

{

throw ex;

}

For your information, my application not uses any web server for the application. Any body can help me please..

shuhada  Tuesday, January 23, 2007 7:27 AM

The problem with throw ex like you've got it is that while it keeps the error, the stack trace is rebuilt from the throw. Instead one should say:

throw;

Which will keep the old stack trace. However the whole catch statement you've got there is a waste of time anyway. You're catching an error just to rethrow it, so what's the point?

Sean Hederman  Tuesday, January 23, 2007 7:41 AM

You can use google to search for other answers

Custom Search

More Threads

• Ending A Process
• Report Services
• Is there a way to fire an event programmatically?
• Limiting Download Size
• Determining Application Startup Form at run time
• DataGridViewColumn.HeaderText
• Keep Modal Form in Focus and Prevent
• Print Preview problem
• datagridview
• ComboBox SelectedIndex code ignored at runtime