Solved

ArrayList property comes out as null

Posted on 2009-04-02
4
337 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Razor DropDownListFor - clear selected in SelectList before creation 3 36
SSRS Deployment problem 5 96
using CK editor in iframes 5 28
orderby list (from Json) 1 30
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

733 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