我有一個C#列表的問題,不知道在向Managepagesid列表中添加一個新對象的時候我錯過了點!c#列出使用For循環添加項目
public class Clients
{
[BsonId]
public string Id { get; set; } //Object ID managed by MongoDb
public string Name { get; set; } //Client Name
public string Phone { get; set; } //Client Phone
public string Email { get; set; } //Client E-mail
public string Username { get; set; } //Client Username
public DateTime LastModified { get; set; } //Client Last Login
public string FB_User_Id { get; set; } //Client FB User ID
public AccessToken UserAccessToken { get; set; } //AccessToken which is stored while user is logged in.
public List<ManagePages> Manage_Pages_id { get; set; } //The pages maintained by the specific client
}
我試圖訪問添加新項目,到ManagePage_id名單,但其thrwing一些空異常..幫助!
Clients client = new Clients();
client.FB_User_Id = FBData.id;
client.Name = FBData.name;
client.Email = FBData.email;
client.Username = FBData.username;
for (int index = 0; index < FBData.accounts["data"].Count; index++)
{
ManagePages pagedetails = new ManagePages()
{
page_id = FBData.accounts["data"][index].id,
page_name = FBData.accounts["data"][index].name,
ManagePages_AccessTokens = new AccessToken()
{
AccessToken_accessToken = FBData.accounts["data"][index].access_token,
AccessToken_expiryDate = DateTime.Now
},
ManagePages_category = FBData.accounts["data"][index].category
};
var category = pagedetails.ManagePages_category;
client.Manage_Pages_id.Add(pagedetails);
}
Stack Trace added added!
異常> System.NullReferenceException引用未設置爲對象的實例。 Vega_MongoDB.FBDataAccess.ClientFBRepository.ClientsData(String accessToken)in g:\ Development \ Vega_MongoDB \ Vega_MongoDB \ FBDataAccess \ ClientFBRepository.cs:line 48 at Vega_MongoDB.Models.ClientRepository..ctor(String connection)in g:\ Development \ Vega_MongoDB \ Vega_MongoDB \ Models \ Clients \ ClientRepository.cs:Vega_MongoDB.Models.ClientRepository.ctor()中的第47行 ,位於Vega_MongoDB的g:\ Development \ Vega_MongoDB \ Vega_MongoDB \ Models \ Clients \ ClientRepository.cs中:第23行 。 Controllers.ClientsController..cctor()在G:\開發\ Vega_MongoDB \ Vega_MongoDB \ \控制器ClientsController.cs:行18
而且我已經檢查了pagedetails對象,它包含了所有的數據..
由於
毗溼奴
你還可以添加stacktrace嗎? –
你在哪裏看到異常? – jrummell