PopUpWindow reference and null object

I have been struggling with this issue for the past few hours but still have no idea what happened. Here's the script:

An application built on top of the Mate framework sometimes needs to communicate with a remote server over a simple binary socket.

When receiving a specific package, I need to switch the view (using the ViewStack) and create a custom panel (using the PopUpManager class). This custom panel contains a dataGrid component that needs to be populated with some XML received along with the specified package.

The problem is that when I try to assign the XML DataGrid to the dataProvider, I keep getting the error "Can't access properties or method of null object reference". The only thing I can think of is some kind of race in event handling and component creation.

Here are the most interesting code snippets:

<!-- LoginEvent.LOGIN_OK _____________________________________________________________________ -->

<EventHandlers type="{LoginEvent.LOGIN_OK}">

    <MethodInvoker generator="{UserManager}" method="storeCurrentUser" arguments="{event.fullName}"/>
    <EventAnnouncer generator="{NavigationEvent}" type="{NavigationEvent.MAIN}"/>
    <MethodInvoker generator="{CustomSocket}" method="listBoards"/>

      

In the above code, I am responding to receiving the LOGIN_OK package.

Save your custom data, change the view, and ask the Socket to send the request (the response for this request is our verySpecificPacket )

Here's the details on how I change the view and create a custom tooltip. In MainUI.mxml:

<mate:Listener type="{NavigationEvent.MAIN}"    method="handleNavigationEvent" />

private function launchBoardListWindow():void {
   Logger.info("launchBoardListWindow()");
   var win:BoardList = PopUpManager.createPopUp(this, BoardList, true) as BoardList;
   PopUpManager.centerPopUp(win);
}

private function handleNavigationEvent(event:NavigationEvent):void {

   viewStack.selectedIndex = MAIN;
   launchBoardListWindow();
}

      

The third position in EventMap is not important, just ask the socket packaging to send some kind of packet. The server is supposed to respond with a verySpecialPacket along with the XML payload. And here we are in the part where the error is. In the mxml describing my custom panel, I am setting a listener for the event that is dispatched after my verySpecialPacket is received .

public function handleListBoardsEvent(e:ListBoardsEvent):void {

   Logger.info("handleListBoardsEvent");        
   xmlData = e.xml;     
   boardList.dataProvider = xmlData.children(); // Here the error!!!
}

      

I really don't get it as xmlData is ok and a custom panel was created with all child components. Thanks for reading!

0


a source to share


1 answer


You are probably on the right track regarding race conditions.

Sentence:

Place a try {...} catch (e: Error) {trace ("error"); } block the code in the handleListBoardsEvent () method.



Then put a breakpoint on trace () and when it hits, take a good look at the various objects.

I am assuming you are trying to access the boardList object prior to creating it - i.e. it is null.

Another possibility is that boardList.dataProvider is the setter and in the customizer it is the code. (Although, if this is the case, I'm sure you would have noticed the stacktrace inFlexBuilder)

0


a source







All Articles