Error: Cannot access a property or method of a null object reference in flex
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 AdvancedData开发者_StackOverflowGridListData).dataField;
}
** here value is comming is null, so i am getting above exception. Please let me know how to fix it.
Thanks, Ravi
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.
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
精彩评论