Click here to Skip to main content
15,885,195 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I had created one user control named as toolbar and one class file named as infocore. The toolbar which is name of user control contain add, save and exit button. The code of add,save and exit button written in infocore class. the save button code written in save(Form f,EventArgs e) function.

Then create object of infocore class in user control and access save() function like objInfocore.save(this.FindForm(),e);

When i add these user control in form and run appliction then i got the exception in program.cs Application.Run(new Form1()) Object reference not set an instance of an object. so what should i pass parameter in Application.Run(new Form1("here Parameter is required?"))
Posted

1 solution

That isn't the problem, so leave that well alone - if your Form1 class constructor required a parameter then the compiler would have complained. "Object reference not set an instance of an object" is a run time error, not compile time, so it is not the Application.Run that is the problem.

Exactly what is the problem is not something I can be precise about - I don't have access to your code. So, you will have to start looking for yourself.

The first thing to do is to find out where the problem is occurring. Since you are talking about Application.Run, I assume that the exception comes when you execute that line - which means that the error is in the constructor somewhere, and the debugger can't work out exactly where. So start off by trapping all exceptions: Look on your VS menu bar under "Debug", "Exceptions..." and put a tick en every check box under "Thrown" and "User-unhandled". Press OK

Now run your app in the debugger and it should stop when it hits the exception, even if some code is catching and re-throwing it.
Looking at the variables in the line throwing the exception should tell you which one is null, and that will at least give you more info as to why it occurred.
 
Share this answer
 
Comments
Mahesh_Bhosale 1-Apr-13 9:05am    
Thank you very much....
OriginalGriff 1-Apr-13 9:10am    
You're welcome!
Sorry I can't be more specific...
Faisalabadians 1-Apr-13 11:33am    
OriginalGriff you always rock dude...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900