首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

如何解决这个异常 ?"An object reference is required for the nonstatic field"

2012-01-29 
怎么解决这个错误 ?An object reference is required for the nonstatic field下面是Vendor.cs文件的内

怎么解决这个错误 ?"An object reference is required for the nonstatic field"
下面是   Vendor.cs文件的内容

开始在开始处声明
private     AcmeReaderLayer   reader1;
//   AcmeReaderLayer   是一个类文件

函数里的一段代码:

byte[]   aa   =   new   byte[36];
                                ApplyPropertyProfileCommand   applyPropertyProfileCommand   =   (ApplyPropertyProfileCommand)command;
                              if   (null   !=   applyPropertyProfileCommand.PropertyProfile)
                                {
                                foreach   (KeyValuePair <PropertyKey,   object>   property   in   applyPropertyProfileCommand.PropertyProfile)
                                {
                                        bool   error   =   false;                                        
                                        try
                                        {
                                              aa=setAppProperty((AcmeReaderLayer)reader1,   (string)property.Key.PropertyName,   (string)property.Value);
  在这错误:     “   Error3An   object   reference   is   required   for   the   nonstatic   field,   method,orproperty   Microsoft.Rfid.Reader.Driver.Acme.VendorHelper.setAppProperty(Microsoft.Rfid.Reader.Driver.Acme.Framework.AcmeReaderLayer,   string,   string) '“
                                        }
                                        catch   (Exception   e)
                                        {
                                                throw   new   ConnectionFailedException( "SetProperty   to   reader   failed ",   e,   " ",   null);
                                        }
                                }

setAppProperty函数声明如下:
internal     byte[]   setAppProperty(AcmeReaderLayer   reader1,   string   propertyName,   string   propertyValue)


                {
                        this.reader1   =   reader1;
                        byte[]   para   =   {   0x01,   0x02   };
                      switch   (propertyName)
                        {
                              case   "ID ":
                              return   para;
                        break;
                    case   "NAME ":
                          reader.name   =   propertyValue;   //TODO:   Currently   unsupported.
        return   para;
                        break;
            }
}


[解决办法]
是不是因为你的reader1没有初始化...
[解决办法]
函数里的一段代码:

aa=setAppProperty((AcmeReaderLayer)reader1, (string)property.Key.PropertyName, (string)property.Value);
在这错误: “ Error3An object reference is required for the nonstatic field, method,orproperty Microsoft.Rfid.Reader.Driver.Acme.VendorHelper.setAppProperty(Microsoft.Rfid.Reader.Driver.Acme.Framework.AcmeReaderLayer, string, string) '“
=================
这段函数代码在什么样的一个函数里
An object reference is required for the nonstatic field
你这段函数是static的???

热点排行