taudep
taudep

Reputation: 2881

Techniques for debugging Flex Framework errors

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

Upvotes: 1

Views: 474

Answers (2)

Orri Scott
Orri Scott

Reputation: 11

I have solved this issue with callLater - do the following... Place a conditional breakpoint in UIComponent.callLater, in the breakpoint condition enter: trace(new Error().getStackTrace()) and viola - every call to callLater from anywhere will dump the dark side of the stack to the trace so you can check it when you get the error.

Hope this helps.

Orri Scott

Upvotes: 1

JeffryHouser
JeffryHouser

Reputation: 39408

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.

Upvotes: 0

Related Questions