Click here to Skip to main content
15,909,645 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi.
I have following code to use in my application but I am unable to solve. Any one help me plz.
My code for class is
C#
namespace Semantics3API
{
    public class Offers
    {
        public string SellerName { get; set; }
        public string Price { get; set; }
        public string Currency { get; set; }
        public string Availability { get; set; }
    }
    //
    public class Stores
    {
        public string SkuInStore { get; set; }
        public string ProductUrlInStore { get; set; }
        public List<Offers> Offers { get; set; }
    }
    //
    public class Images
    {
        public string imageUrl;
    }
    //
    public class Product
    {
        public string Title { get; set; }
        public List<Images> Images { get; set; }
        public List<Stores> Stores { get; set; }
    }
}

And here is the error null reference

C#
Stores store = new Stores();
store.SkuInStore = skuInStore;
store.ProductUrlInStore = productUrlInStore;
Offers offer = new Offers();
offer.SellerName = sellerName;
offer.Price = price;
offer.Currency = currency;
offer.Availability = availability;
//adding offer to store
store.Offers.Add(offer); // object reference not set to instance of object error :(
Posted
Updated 9-Feb-14 9:32am
v2

1 solution

C#
public class Stores
{
  public Stores()
  {
    Offers = new List<Offers>();
  }
  public string SkuInStore { get; set; }
  public string ProductUrlInStore { get; set; }
  public List<Offers> Offers { get; set; }
}
 
Share this answer
 
v2
Comments
Asad Nawaz 9-Feb-14 15:47pm    
Thank you very very much :). It solved my problem :) Thumbs up
Kornfeld Eliyahu Peter 9-Feb-14 15:52pm    
I'm glad to help...
Asad Nawaz 9-Feb-14 16:00pm    
This was my first question ever on the Internet :)
and very fast response within 5 minutes.
I was trying to fix for last 2 hours. After then I think I should post my own question :)
Kornfeld Eliyahu Peter 9-Feb-14 16:06pm    
Don't get used to it - 5 minutes isn't the average...
Asad Nawaz 9-Feb-14 16:11pm    
Thank you. I know working by self try is the Key for learning :)
Ok

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