2013-05-27 167 views
-2

我有一个静态类和只读属性未将对象引用设置为对象的实例。 C#.NET

public class ClaSearchUser 
{ 
    public ClaSearchUser() { } 


    public struct Attributes 
    { 
     public static readonly Attribute EMAIL_ADRESS; 
     public static readonly Attribute FIRST_NAME; 
     public static readonly PuzzleAttribute STATUS; 
    } 
} 

但是,当我做它用,我得到的电子邮件行错误。

foreach (DataRow mRow in data.Table.Rows) 
     { 
     String id = mRow[AttributeManager.Common.Ident.Name].ToString(); 
     String user_oid = mRow[AttributeManager.Common.Oid.Name].ToString(); 
     String email = mRow[ClaSearchUser.Attributes.EMAIL_ADRESS.Name].ToString(); 

     } 

在此先感谢

+0

在哪一行发生错误? – jAC

+1

你的其中一个变量为空,就是错误说的。请放置一个断点并遍历代码;我们不能为你做到这一点。 – CodeCaster

回答

1

您正试图访问null变量的成员变量或方法。

这里是所有变量的列表,这可能null会抛出异常,如果他们是:

  • AttributeManager.Common.Ident
  • AttributeManager.Common
  • AttributeManager
  • MROW [AttributeManager.Common.Ident.Name]
  • AttributeManager.Common.Oid
  • MROW [AttributeManager.Common.Oid.Name]
  • ClaSearchUser.Attributes.EMAIL_ADRESS
  • ClaSearchUser.Attributes
  • ClaSearchUser
  • MROW [ClaSearchUser.Attributes.EMAIL_ADRESS.Name]

哪一个真正null,是你的工作,找出。

1

ClaSearchUser.Attributes.EMAIL_ADRESS.Name将导致在给定的异常,当你不设置EMAIL_ADRESS的值。

或者它可能是您正在尝试阅读的其他Name的任何一个。

1

ClaSearchUser.Attributes.EMAIL_ADRESS.Name将抛出一个NullReferenceException,如果EMAIL_ADRESS为空。 mRow[ClaSearchUser.Attributes.EMAIL_ADRESS.Name]也可以为空,这会导致.ToString()抛出NullReferenceException。

相关问题