473,756 Members | 5,129 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I am "Object reference not set to an instance of an object."/SubForm/MainForm/busObje

I am getting the error "Object reference not set to an instance of an object." after launching a child form by a click of a button, reason why I know of is due to setting MdiParent to Null in order to launch this new form which leads to nulling out the reference of the busObject/main form, how can I restore the busObject/main form and avoid the error?

Here is some code:

1) Here where the new/child form is being launched:
Expand|Select|Wrap|Line Numbers
  1.             Form newForm = new QueryResearchGridControl();
  2.             newForm.MdiParent = null;
  3.             newForm.TopLevel = true;
  4.             newForm.ShowDialog();
  5.             newForm.MdiParent = this;
2) Here is some code from QueryResearchGr idControl():
Expand|Select|Wrap|Line Numbers
  1.   //This was a Control, now it is a form with a Control:
  2.     public partial class QueryResearchGridControl : Form   
  3. {
  4.  
  5.         public QueryResearchGridControl()
  6.         {
  7.             TopLevel = false;
  8.             InitializeComponent();
  9.  
  10.         }
  11.  
  12.         private IResearchGridBusinessObject busObject;
  13.         private BaseResearchGridForm myParent;
  14.  
  15.     public void Initialize(BaseResearchGridForm parent)   
  16.     {
  17.             myParent = parent;
  18.             busObject = parent.BusinessObject;
  19.     }

So as you probably notice that when MdiParent is being nulled out in item 1 above, it is causing the busObject to be null.
Oct 4 '10 #1
2 2025
Joseph Martell
198 Recognized Expert New Member
You could add a ParentChanged event handler to your child form. That way you avoid the null reference exception, but your code would still execute when the parent is eventually set.
Oct 5 '10 #2
I am re writing my reply in case previouse one did not post.

Hello Joseph,

Thank you for the feedback, I found out that mdiPrent has nothing to do with what I was doing so I removed it from my code, after further research I found out that I need to instantiate the busObject, allow me to explain, when the main form is launched (BaseResearchGr idForm), a button is clicked to launch another form that hosts a control (newForm/QueryResearchGr idControl), all is working well so far, but once I click the "Search" button on the new form (newForm/QueryResearchGr idControl) I get the error (null reference....) at the busObject assignments...e tc. I need to instantiate the busObject but I am new in c#/OO in general so I wonder if you can make some further recommendations . Thanks in advance.
Oct 6 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2752
by: Bob Cannistraci | last post by:
A three-tier user authentication system was running without a problem for almost a year and now is suddenly dysfunctional. We don't know of any changes to any of the servers. It's quite maddening. The details: 1) We know the COM+ app is instanced on the COM+ server (Win 2000). The component graphic spins when CreateObject is called. 2) The proxy is installed on an IIS server (Win 2000) with delivers the interface, written in ASP, to the...
1
6069
by: vijay | last post by:
Hi I am working on a web application. I have huge form where in I have filled some part of the form and after two hours again I started filling the rest of the form but I got the following error Server Error in '/abc' Application Server Error in '/abc' Application >> Object reference not set to an instance of an object. >> Description: An unhandled exception occurred during the execution o >> the current web request. Please review...
1
2832
by: Chris Magoun | last post by:
I suddenly received an unexpected error in my project. I have been working on this project for some time without this issue. Nothing has changed in the form that caused the exception. A little experimentation shows that I cannot run ANY .NET web project without getting this error: ---------------------------------------------------------------------------- ---- Object reference not set to an instance of an object.
18
28758
by: Microsoft | last post by:
When I try this in my code I alwas get an errormessage: "Object reference not set to an instance of an object" Dim g As System.Drawing.Graphics g.DrawString("Test", New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 0, 0) Why is this? Marc
9
5111
by: MrSpock | last post by:
1. Create a new Windows Application project. 2. Open the project properties and check "Make single instance application". 3. Build. 4. Go to the release folder and run the application. 5. Try to open a second instance of the application. This will cause an unhandled exception and the "Send Error Report" box shows up. Does this happen to anyone else, or is it just me? Debug info: "Unhandled exception at 0x00e149fd in...
1
2509
by: DaveO. | last post by:
Hello, I'm calling a VB.NET web service, also from VB.NET, and I get the error " Object reference not set to an instance of an object" on the following line in Reference.vb, when it tries to make the call: Dim results() As Object = Me.Invoke("Phys_Post", New Object() {SessionID, a, b, c, d, CountList}) I can call other web services I've written just fine. This one is more
2
2977
by: louie.hutzel | last post by:
This JUST started happening, I don't remember changing any code: When I click the submit button on my form, stuff is supposed to happen (which it does correctly) and a result message is posted back to the same page at the top of my form alerting the user that their request has been approved or denied. However, the end result is an error message: Error Message: Object reference not set to an instance of an object.
0
2215
by: =?Utf-8?B?SkhhbGV5?= | last post by:
Our system is: IIS Server: dual Intel Xeon 2.80 GHz, 4 GB Ram Windows Server 2003 SP2 IIS 6.0 SQL Server: dual Intel Xeon 2.80 GHz, 4 GB Ram (separate server) Windows Server 2003 SP2 SQL Server 2000 We are having some problems with a website we are developing, and had some
0
2653
by: Tamer Ibrahim | last post by:
Hi, Sometimes, I got the following error message when I use ajax calendar control on some aspx pages : Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an...
2
2204
by: Monty | last post by:
I'm installing an ASP.Net 2.0 web applications project (WAP) application on a production server (Win 2003). I've installed it on XP test machines before and it runs fine. On my production machine I get this error (full error screen below) when I attempt to visit the start page. The type ("MyCo.Ing.MyAppRoleProvider") is in my main assembly in the \bin folder. Can anyone tell me what I'm doing wrong or what I should check? TIA. Server...
0
9271
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10031
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9838
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8709
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7242
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5140
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2665
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.