0
votes

I am having an error when using a dateFormatter in Flex 4 to format column of a Flex Datagrid.

The function is as follows:

public function dataGridFormatDateLabelFunction2(item:Object, dgColumn:Object):String
{
    var ret:String = "";
    var dt_len:Number = String(item[dgColumn.dataField]).length;

    if (dt_len > 4)
    {
        var date:Date=mx.controls.DateField.stringToDate(String(item[dgColumn.dataField]),"YYYY-MM-DD");
        ret = UIUtils.formatDate(date, "DD-MMM-YYYY");
    }
    return ret;     
}



But I am getting the following error:

TypeError: Error #1009: Cannot access a property or method of a null object reference. at mx.formatters::DateBase$/http://www.adobe.com/2006/flex/mx/internal::extractTokenDate()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\formatters\DateBase.as:450] at mx.formatters::StringFormatter/formatValue()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\formatters\StringFormatter.as:126] at mx.formatters::DateFormatter/format()[E:\dev\4.5.1\frameworks\projects\framework\src\mx\formatters\DateFormatter.as:640] at com.flexicious.utils::UIUtils$/formatDate()

Can someone please help me with this error? How can I handle it?

Thanks for your input.

1
Could you show your data to let us now which values the columns have? The best way would be to show the whole application so that we can try it by ourselves. - Anton

1 Answers

0
votes

Your date is not in "YYYY-MM-DD" and you are parsing it using that format.