ArrayList property comes out as null

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

public ArrayList basketPayments

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

 Basket.PaymentMethod = card;

but the second like Basket.basketPayments.Add(card);  gives me object null error. How can I use it??
Question by:Camillia
  • 2
LVL 16

Assisted Solution

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

Expert Comment

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

Accepted Solution

JimBrandley earned 300 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
           if (mBasketPayments == null)
                mBasketPayments = new ArratList(10);
           return mBasketPayments;
     set { mBasketPayments = value; }


Author Comment

ID: 24055414
thanks, let me try.

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now