如何解决这个错误 [英] How to solv this error

查看:74
本文介绍了如何解决这个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我试图将一个参数传递给当前班级中另一个班级的方法

所以,我是使用构造函数来做它

在下面的代码中我创建了构造函数类的新实例,然后尝试将字符串传递给方法



  class  GatewayMsgIDs:表格
{

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







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



我收到如下错误



对象参考非静态字段,方法或属性需要





谢谢

John

解决方案

我们无法确切地说 - 因为我们无权访问您正在运行的代码。

您这样做 - 所以请使用调试器。在该行上放置一个断点:

 GWMsgDetails = SCANLA.GatewayMsgIDs.ResponseTimeofMsgs(numofBusesandColor.numofbuses); 

并运行您的程序。

当它到达断点时,使用调试器按顺序查看每个部分,从左边开始:

 SCANLA 
SCANLA.GatewayMsgIDs

它们的Onle将为null,或者将返回null。然后,您只需查看代码并找出原因。


我们不能:我们无法访问您的硬盘!


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

class GatewayMsgIDs : Form
    {

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




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

解决方案

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:

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!


这篇关于如何解决这个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆