views:

59

answers:

2

Hi,

Getting error while run the checkBox item renderer in advanced datagrid with out data. Error: Cannot access a property or method of a null object reference.

Please find the below code:

**

public function set listData(value:BaseListData):void
            {   

            _listData=value;                
            _dataGrid=value.owner as AdvancedDataGrid;
            _dataField=(value as AdvancedDataGridListData).dataField;

            }

** here value is comming is null, so i am getting above exception. Please let me know how to fix it.

Thanks, Ravi

+1  A: 

Check for null before trying to access properties of value:

_dataGrid = value != null ? value.owner as AdvancedDataGrid : null;
_dataField = value != null ? (value as AdvancedDataGridListData).dataField : null;

This way _dataGrid and _dataField will just get set to null if value is null, avoiding your runtime error.

Hope that helps.

Wade Mueller
A: 

I'm confused.

First, the checkbox already contains a listData property, inherited from Button: http://livedocs.adobe.com/flex/3/langref/mx/controls/Button.html#listData . Why do you need to implement a new one?.

Second, the itemRenderer's ListData property already gives you access to the listData properties. Why do you need to store them locally in the renderer?

http://livedocs.adobe.com/flex/3/langref/mx/controls/advancedDataGridClasses/AdvancedDataGridListData.html

www.Flextras.com