tags:

views:

43

answers:

2

Every now and then I come across an exception being thrown by the Flex framework. Often from ListBase code that renders itemRenderers and such. I'm looking for techniques to use to figure out even which of my ListBase instances is even throwing the error.

The difficulty arises when the top of the call stack originates in a callLaterDispatcher()

TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at mx.controls.listClasses::ListBase/addToFreeItemRenderers()
    at mx.controls.listClasses::ListBase/reduceRows()
    at mx.controls.listClasses::ListBase/updateDisplayList()
    at mx.controls.listClasses::TileBase/updateDisplayList()
    at mx.controls.listClasses::ListBase/validateDisplayList()
    at mx.managers::LayoutManager/validateDisplayList()
    at mx.managers::LayoutManager/doPhasedInstantiation()
    at Function/http://adobe.com/AS3/2006/builtin::apply()
    at mx.core::UIComponent/callLaterDispatcher2()
    at mx.core::UIComponent/callLaterDispatcher()

In looking at a breakpoint in that I set in ListBase::addToFreeItemRenderers, I can see that the item is null that's being passed to the function, as so:

protected function addToFreeItemRenderers(item:IListItemRenderer):void
{
    // The following item is NULL when the exception is being thrown...
    if (item == null) return;

    DisplayObject(item).visible = false;

    var factory:IFactory = factoryMap[item];    
...

How do I figure out what I need to figure out? I've solved similar issues before, but I had to use magic and voodoo and take guesses and throw in callLater calls in my code to fix.

Thanks

A: 

I usually launch the app in debug mode. When the error occurs, debug mode should take over.

In Debug mode you can:

  1. Look at the stack trace and drill back down to the component in question. In some cases, such as binding or collectionChange events this won't help. As you discovered, callLater makes this difficult.

  2. Add a watch variable name or id which can tell you the component's name, which you can them tie back to the location. If you are using the same name in multiple places, this might not be definitive, though.

Beyond, when I come across errors like this; they are often due to something I did, and correcting that something fixes the error for good. However, it can be tough to figure out what the cause is.

www.Flextras.com
I was hoping there was more that could be done. But this is the best I could ever come up with: 1) set breakpoint in base Flex Framework code 2) trace back to parent component via id or name properties 3) work magic to figure it out.
taudep
A: 

Lunch on debug mode and put a brakepoint on the function addToFreeItemRenderers

mazgalici
Evidently you didn't read my question, nor any of the thread or comments, as its obvious that I've already done this.
taudep