views:

31

answers:

2

I'm using a List which I need to be empty at the start. I'm adding items to it as needed by clicking a button. Since it's empty, I haven't added a dataProvider property

<s:List id="thelist" itemRenderer="listIR" />

To add an item, I'm adding it to the dataProvider directly

thelist.dataProvider.addItem()

but when I do that, it gives me this error

 #1009: Cannot access a property or method of a null object reference.

Also I have a debugging Alert in the listIR itemRenderer itself and I see that when the list is created, I get that alert twice as if 2 itemRenderers were created, even though the list is supposed to be empty at the start.

Any ideas what's wrong with this itemRenderer? How do I start with an empty dataProvider and add items smoothly to it?

A: 

The dataProvider of the List ist null. You have to set an empty implementation of the IList or ICollectionView interface, e.g.:

<s:List id="thelist" itemRenderer="listIR" dataProvider="new ArrayCollection()"/>
Daniel Engmann
A: 

Because there was not thelist.dataProvider set then this value is initially null. so null.addItem() is not possible.

You should have see at debug time an instantiated Array or ArrayCollection as dataProvider before calling the addItem();

fix 1: described by << Daniel Engmann >>

fix 2:

if(!thelist.dataProvider) thelist.dataProvider = new ArrayCollection();
thelist.dataProvider.addItem();
Adrian Pirvulescu