Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 30th, 2006, 12:34 AM
Registered User
 
Join Date: Nov 2004
Location: Bangalore, Karnataka, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Unhandled NullReference Exception

Hello people,

I am finding a hard time in resolving the nullreferenceexception my application is throwing.

My application has two forms.
In the first form i am performing the following operations.
1. Fetching values from the database
2. Creating an instance of the second form
3. Making the first form invisible
4. Making the second form visible
5. Navigating to second form by calling a method in which i am
   populating the data fetched from database into a list view control

These are the steps that are executed in my application. Now in the first two runs i am able to display fetched data in the second form and navigate back to the first form through a button_click event where in i am making the second form invisible and making the first form visible(only single instance created for both forms). When i perform the operation for the third run the second form is loaded with data and immediately breaks giving the "
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object."
The stack trace is as follows ---
************************************************** ********************
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
   at System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeMethods+IMsoComponentManager. FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.Run(Form mainForm)
   at App.SearchCriteria.Main() in D:\App\Search.vb:line 5The program '[3436] App.exe' has exited with code 0 (0x0).
************************************************** ********************

I have checked the control flow and its complete. The control comes back to the event which fired the search on the first form and after it exits this event this exception is thrown. This occurs every third run i perform a search. In the first two runs i am not facing any problem but in the third run i am facing this exception.

Can any one help me in resolving this issue as i am running short of time.

Thanks in advance
dheeraj
 
Old May 30th, 2006, 05:55 PM
Authorized User
 
Join Date: May 2006
Location: Chico, CA, USA.
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is difficult to debug w/o seeing the code. What you should do is set a break point somewhere near where you suspect the problem lies, and then run the program using the debugger (F5). After the program stops on the breakpoint, trace through (F10) until you reach the bugger line.

Brandon




Similar Threads
Thread Thread Starter Forum Replies Last Post
unhandled exception dipakp ASP.NET 2.0 Professional 1 July 6th, 2007 02:16 PM
Null reference exception was unhandled labby C# 2005 0 April 24th, 2007 06:14 AM
Unhandled NullReference Exception MAKO C# 1 April 19th, 2006 05:46 AM
Unhandled Exception stu9820 ASP.NET 1.0 and 1.1 Basics 11 January 14th, 2004 05:55 PM
Unhandled Exception: mbarrett C# 3 August 1st, 2003 05:25 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.