tag:robotlegs.tenderapp.com,2009-10-18:/discussions/problems/11-after-view-arrives-onstage-and-instantiates-the-context-i-get-an-null-object-reference-errorRobotlegs: Discussion 2018-10-18T16:35:06Ztag:robotlegs.tenderapp.com,2009-10-18:Comment/6305372009-11-24T18:11:07Z2009-11-24T21:49:26ZAfter view arrives onstage and instantiates the context, I get an Null Object Reference error<div><p>My view instantiates the context like so:<br></p>
<pre>
<code> mx:Module xmlns:mx="http://www.adobe.com/2006/mxml"
width="100%"
height="100%"
xmlns:ui="com.ecommerce.imperia.ui.*"
xmlns:controls="com.ecommerce.imperia.controls.*"
xmlns:maps="com.ecommerce.imperia.cron.*"
implements="com.ecommerce.imperia.common.interfaces.ICronModule"
preinitialize="onPreInitialize()">
<mx:Style source="../assets/cronStyle.css"/>
<mx:Script>
<![CDATA[
private function onPreInitialize():void //sets this context for this.
{
context = new CronContext(this);
}</code>
</pre>
<p>Now the context never seems to reach it's startup method. It
always<br>
seems to fail in the call to super in the contructor. here is
my<br>
code:</p>
<pre>
<code> public function CronContext(contextView:DisplayObjectContainer)
{
super(contextView, true);
}
override public function startup():void
{
// View - because the view is already On Stage, I need to use mediatorMap.createMediator.
mediatorMap.mapView(this.contextView,
CronModuleMediator,ICronModule);
mediatorMap.createMediator(this.contextView);</code>
</pre></div>levi.stropetag:robotlegs.tenderapp.com,2009-10-18:Comment/6305372009-11-24T18:18:09Z2009-11-24T18:19:39ZAfter view arrives onstage and instantiates the context, I get an Null Object Reference error<div><p>Hi Levi</p>
<p>where is your:<br>
import yourPathTo.CronContext;<br>
private var context:CronContext;</p>
<p>Ondina</p></div>Ondina D.F.tag:robotlegs.tenderapp.com,2009-10-18:Comment/6305372009-11-24T18:19:45Z2009-11-24T18:22:31ZAfter view arrives onstage and instantiates the context, I get an Null Object Reference error<div><p>Hmm.. very strange indeed.</p>
<p>For the MXML part, you could remove the preinitialize handler,
and instead use the MXML-friendly form:</p>
<p><ns:CronContext view="{this}" /></p>
<p>On the concrete Context side you'd need to remove the
constructor for this to work (or make sure the all the ctor args
are optional). Also, you shouldn't need to manually create a
Mediator for the contextView anymore - we added a feature to handle
auto creation of the mediator if the view that gets mapped happens
to be the contextView.</p>
<p>Could you try those changes and let us know how it goes?</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/6305372009-11-24T19:20:36Z2009-11-24T19:20:36ZAfter view arrives onstage and instantiates the context, I get an Null Object Reference error<div><p>@ondina you don't need a var reference (unless you want access
to it)</p>
<p>I've tried to reproduce this with no success. Perhaps you can
strip out your proprietary code and post an FXP/zip of the project
for me to investigate.</p></div>Joel Hookstag:robotlegs.tenderapp.com,2009-10-18:Comment/6305372009-11-24T19:33:45Z2009-11-24T19:33:45ZAfter view arrives onstage and instantiates the context, I get an Null Object Reference error<div><p>With that style of initialisation you do need to keep a ref to
the<br>
context - or it will be eaten during garbage collection.</p></div>Shaun Smithtag:robotlegs.tenderapp.com,2009-10-18:Comment/6305372009-11-24T19:34:53Z2009-11-24T19:34:53ZAfter view arrives onstage and instantiates the context, I get an Null Object Reference error<div><p>oh, jeez. Good point!</p></div>Joel Hookstag:robotlegs.tenderapp.com,2009-10-18:Comment/6305372009-11-24T20:42:58Z2009-11-24T21:49:26ZAfter view arrives onstage and instantiates the context, I get an Null Object Reference error<div><p>Thank you all for the input.</p>
<p>Shaun hit the nail right on the head. I was doing a combination
of things that I gleened from different demos and they didn't jive
well.</p>
<p>I took the Views's 'onpreinitilize' function out, and replaced
it with Shaun's recommendation of '<ns:CronContext view="{this}"
/>'</p>
<p>Also - I took out the manually created mediator for
'contextView'.<br></p>
<p>The real reason why all this didn't work was the inclusion of
the constructor logic in my 'Context'. Once removed everything was
working great!</p>
<p>Thank you guys for the swift responses. Much appreciated.</p>
<p>-Levi</p></div>levi.strope