?
Solved

ArrayList property comes out as null

Posted on 2009-04-02
4
Medium Priority
?
339 Views
Last Modified: 2012-08-14
I have a class: Basket.cs and i created a property for it like this:

public ArrayList basketPayments
        {
            get;
            set;
        }

In my page1.aspx, I want to populate this arraylist so I did this:

 Basket.PaymentMethod = card;
 Basket.basketPayments.Add(card);

but the second like Basket.basketPayments.Add(card);  gives me object null error. How can I use it??
0
Comment
Question by:Camillia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 16

Assisted Solution

by:burakiewicz
burakiewicz earned 800 total points
ID: 24054578
try this
Basket.PaymentMethod = card;
 Basket.basketPayments=new ArrayList();
 Basket.basketPayments.Add(card);
0
 
LVL 16

Expert Comment

by:burakiewicz
ID: 24054584
or on the constructor for your basket class add
basketPayments=new ArrayList();
0
 
LVL 22

Accepted Solution

by:
JimBrandley earned 1200 total points
ID: 24054593
It has not been initialized. So, your first get returns the null.

In the class that contains this, add a member:
private ArrayList mBasketPayments = null;

Then change the getter and setter as:

public ArrayList basketPayments
{
      get
     {
           if (mBasketPayments == null)
                mBasketPayments = new ArratList(10);
           return mBasketPayments;
     }
     set { mBasketPayments = value; }
}

Jim
0
 
LVL 7

Author Comment

by:Camillia
ID: 24055414
thanks, let me try.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question