Solved

ArrayList property comes out as null

Posted on 2009-04-02
4
330 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
  • 2
4 Comments
 
LVL 16

Assisted Solution

by:burakiewicz
burakiewicz earned 200 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 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
{
      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

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 (https://www.paessler.com/prtg). 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