Model not being injected

Joe's Avatar

Joe

30 Jun, 2011 06:25 PM

My model does not seem to get injected into my service class, I keep getting a Cannot access a property or method of a null object reference error.

in my context I have the following:
injector.mapSingleton(MenuModel);

in my service class I Inject the model like so:
[Inject] public var model:MenuModel;

Am i missing something?

  1. 1 Posted by Paul Robertson on 30 Jun, 2011 06:58 PM

    Paul Robertson's Avatar

    A couple of other "easily to overlook" things to check:

    - Is your Service class mapped (e.g. using injector.mapSingleton()) or
    are you creating an instance yourself?

    - In your Service class, are you accessing "model" in the constructor?
    Injected properties aren't available in the constructor (you can use a
    method marked with [PostConstruct] instead).

    Paul

  2. Support Staff 2 Posted by Stray on 30 Jun, 2011 07:56 PM

    Stray's Avatar

    Hi Joe - incase what Paul has said doesn't cover it - we have a section on null injection errors in our 'common problems' document:

    https://github.com/robotlegs/robotlegs-framework/wiki/common-problems

  3. 3 Posted by visnik on 30 Jun, 2011 07:59 PM

    visnik's Avatar

    Paul,

    I found the problem, I was creating an instance my self in my command. Thanks.

  4. Stray closed this discussion on 01 Jul, 2011 10:03 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac