zell71
asked on
System.NullReferenceException was unhandled
Hi all,
i'm getting this error and im trying everything to resolve it. below is the code that is the problem.
when i run it,
this.HeadersNeededSearch(m yHeaderDat a);
pulls back the following error:
"System.NullReferenceExcep tion was unhandled"
- "Object reference not set to an instance of an object."
Basically, what it does, passes a number of variables into a <list>.
any ideas where this is wrong?what am i missing?
i'm getting this error and im trying everything to resolve it. below is the code that is the problem.
when i run it,
this.HeadersNeededSearch(m
pulls back the following error:
"System.NullReferenceExcep
- "Object reference not set to an instance of an object."
Basically, what it does, passes a number of variables into a <list>.
any ideas where this is wrong?what am i missing?
public delegate void HeadersNeededSearchHandler(HeaderSearchData e);
public event HeadersNeededSearchHandler HeadersNeededSearch;
private void HeaderSearch(ManagementInterfaces.EDIStatusSelection HeaderStatus, DateTime OrderDate, string SupplierID, string PONo)
{
this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
HeaderSearchData myHeaderData = new HeaderSearchData();
HeadersNeededSearchHandler test = HeadersNeededSearch;
myHeaderData.HeaderStatus = HeaderStatus;
myHeaderData.TargetDate = OrderDate;
myHeaderData.SupplierID = SupplierID;
myHeaderData.PONo = PONo;
this.HeadersNeededSearch(myHeaderData);
this.NoOrdersSearchLabel.Visible = !(myHeaderData.HeaderCount > 0);
this.OrderSearchView.DataSource = myHeaderData.Headers;
this.Cursor = System.Windows.Forms.Cursors.Default;
}
The error is in side the HeadersNeededSearch find this method and add a break line on the first line of code inside the method and then step over(F10), otherwise break no the HeaderNeedSearch(myHeaderD ata) and step into (F11) rather than step over this line.
this.headerneededsearch(my headerdata )
here the object is referring a null object , , , i'm sure i will get an error.
here the object is referring a null object , , , i'm sure i will get an error.
asker has that object instantiate before making that call -- as well as setting property values, so it shouldn't be null.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok intrwrks, firstly HeadersNeededSearchHandler test = HeadersNeededSearch; was used as testing and not removed for purpose for you guys to see..so that can be ignored.
using your method, it works and passes over this.HeadersNeededSearch(m yHeaderDat a);
however doesnt return expected data, any other suggestions out there please feel free to post. im just testing over code
using your method, it works and passes over this.HeadersNeededSearch(m
however doesnt return expected data, any other suggestions out there please feel free to post. im just testing over code
What do you mean it doesn't return the expected data? Do you mean the event is not firing?
If the HeadersNeededSearch is null, then that means the form or class using the control has not subscribed to the event properly.
Are you subscribing to the event somewhere in your code? Example in code window.
If the HeadersNeededSearch is null, then that means the form or class using the control has not subscribed to the event properly.
Are you subscribing to the event somewhere in your code? Example in code window.
void someFunction()
{
YourCustomControl.HeadersNeededSearch += new HeadersNeededSearchHandler(YourCustomControl_HeadersNeededSearch);
}
protected void YourCustomControl_HeadersNeededSearch(object sender, HeaderSearchData e)
{
// process data here
}
ASKER
abit of background..it was a project left last year, so i've been asked to pick it up and finish it.
I think your right..its not hitting this..which is surely the event.
so
YourCustomControl.HeadersN eededSearc h += new HeadersNeededSearchHandler (YourCusto mControl_H eadersNeed edSearch); is the subscription code?
I think your right..its not hitting this..which is surely the event.
so
YourCustomControl.HeadersN
class clsServerConnection
{
public clsServerConnection(EDIManagementConsole FormToConnect)
{
FormToConnect.HeadersNeededSearch += new EDIManagementConsole.HeadersNeededSearchHandler(HandleHeadersNeededSearch);
}
...
That code should subscribe to the event as long as the value passed into the Constructor is a reference to the proper control. You should then have a function in that class named HandleHeadersNeededSearch that would actually handle the event and receive the appropriate data.
Jason
Jason
protected void HandleHeadersNeededSearch(object sender, EDIManagementConsole.HeaderSearchData e)
{
// handle data.
// e should contain the values from the event.
}
ASKER
Jason, cheers mate, a little bit of backwards engineering sorted it.
Basically, gonna have to scrap the events and start it in my way.
i have it working now so if i want to call from events i can do it once i got more time.
A rating because you replied fast and VERY helpful. your a star *
Basically, gonna have to scrap the events and start it in my way.
i have it working now so if i want to call from events i can do it once i got more time.
A rating because you replied fast and VERY helpful. your a star *
this.HeadersNeededSearch(m