Click here to Skip to main content
15,898,670 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I am trying to pass a argument into a method of another class from the current class
So, I am using constructor for doing it
In the below code I am creating new instance of constructor class and then trying to pass string into the method

C#
class GatewayMsgIDs : Form
    {

      public List<GatewayMessageDetails> ResponseTimeofMsgs( string NumofBuses)
        {
         //mycode
         }
     }



C#
class GatewayResponseTime
    {
 private void GenerateExcelSheets(Excel.Worksheet xlWorkSheet, string sheetname, string noofBuses)
        {
 GWMsgDetails = SCANLA.GatewayMsgIDs.ResponseTimeofMsgs(noofBuses);
        }
    }

I am getting error like below

An object reference is required for the non-static field, method, or property


Thanks
John
Posted
Updated 14-Feb-14 3:10am
v5
Comments
ZurdoDev 14-Feb-14 8:06am    
You have to call new on whatever it is complaining about.
Bala Selvanayagam 14-Feb-14 8:22am    
where do you instantiate SCANLA

You may have to post your code showing both classes and the way you are calling. Without this we would not be able to figure out
Member 10408451 14-Feb-14 9:11am    
Hi,
I updated my question with my code
please check it
If not possible to say with that, I will try to post my whole code

1 solution

We can't tell, exactly - because we don't have access to your running code.
You do - so use the debugger. Put a breakpoint on the the line:
C#
GWMsgDetails = SCANLA.GatewayMsgIDs.ResponseTimeofMsgs(numofBusesandColor.numofbuses);
and run your program.
When it hits the breakpoint, use the debugger to look at each part in sequence, starting from the left:
SCANLA
SCANLA.GatewayMsgIDs
Onle of them will be null, or will return null. Then all you have to do is look through your code and find out why.

We can't: we don't have access to your HDD!
 
Share this answer
 

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