inject - Roboguice 2.0 (android): POJO injection error (always null) -


my base pojo class:

public class basedao {    public basedao() {    }    // ...  } 

my extends pojo class:

public class kelvindao extends basedao {    public kelvindao () {       super();    }    // ...  } 

i want use kelvindao in service that:

public class hankelvinhandler extends httprequesthandler {     @inject    private kelvindao mkelvindao;     public void treatget() {       mkelvindao.blabla(); !!! mkelvindao null    } 

it's simple doesn't work :(

thank guys help!

how creating hankelvinhandler? if you're doing within subclass of roboguice class, such roboactivity, should work. example:

public class myactivity extends roboactivity {     @inject     private hankelvinhandler m_handler;     [...] } 

otherwise (i.e., you're creating within pojo), you're in regular guice land, , believe need use injector instance of it. example:

public class myclass {     public void dosomething()     {         injector injector = guice.createinjector( new yourguicebindings() );         hankelvinhandler handler = injector.getinstance( hankelvinhandler.class );         handler.treatget(); // mkelvindao should     } } 

if haven't seen use of injector before, or don't know put yourguicebindings(), may need read following:

https://github.com/roboguice/roboguice/wiki/simple-custom-binding

https://code.google.com/p/google-guice/wiki/gettingstarted

it seems there should way without using injector, don't know.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -