android - Dagger 2 error: dependency "cannot be provided without an @Inject constructor" while it actually annotated with @Inject -


i've started using dagger 2 , faced strange issue looks bug me.

i have 3 modules, composed 1 subcomponent, in turn extends/pluses higher level component.

subcomponent pretty simple: combination of modules , single injection point:

@singleton @subcomponent(         modules = {                 navigationdrawermodule.class,                 navigationlistmodule.class,                 switchermodule.class         } ) public interface navigationdrawercomponent {       navigationdrawerfragment inject(navigationdrawerfragment object);  } 

first modules looks - provides general fragment-level dependencies:

@module public class navigationdrawermodule {      private final activity activity;     private final view rootview;     private final loadermanager loadermanager;      public navigationdrawermodule(activity activity, view rootview, loadermanager loadermanager) {         this.activity = activity;         this.rootview = rootview;         this.loadermanager = loadermanager;     }      @provides @singleton eventbus providelocalbus() {         return eventbus.builder().build();     }      @provides @singleton view provideviewroot() {         return rootview;     }      @provides @singleton loadermanager provideloadermanager() {         return loadermanager;     }      @provides @singleton context providecontext() {         return activity;     } } 

second module looks - provides presenter/controller , dependencies subset of ui on screen:

@module public class switchermodule {      @provides switchcontroller provideswitchercontroller(switchcontrollerimpl impl) {         return impl;     }      @provides switcherview provideswitcherview(switcherviewimpl impl) {         return impl;     }  } 

third module - presenter/controller subset of ui:

@module public class navigationlistmodule {      @provides @singleton navigationlistcontroller providenavigationlistcontroller(navigationlistcontrollerimpl impl) {         return impl;     }      @provides @singleton navigationlistview providenavigationlistview(navigationlistviewimpl impl) {         return impl;     } } 

relevant part of fragment being injected:

@inject switchcontroller identityswitchcontroller; @inject switcherview identityswitcherview; @inject navigationlistcontroller navigationlistcontroller; @inject navigationlistview navigationlistview; 

navigationlistcontrollerimpl implements following constructor:

@inject public navigationlistcontrollerimpl(context ctx, eventbus bus) {     this.ctx = ctx;     this.bus = bus; } 

error i'm getting dagger 2 compiler following:

error: ...sidenavigation.navigationlist.navigationlistcontrollerimpl cannot provided without @inject constructor or @provides-annotated method. ...sidenavigation.navigationdrawerfragment.navigationlistcontroller [injected field of type: ...sidenavigation.navigationlist.navigationlistcontroller navigationlistcontroller] ...sidenavigation.navigationlist.navigationlistmodule.providenavigationlistcontroller(...sidenavigation.navigationlist.navigationlistcontrollerimpl impl) [parameter: ...sidenavigation.navigationlist.navigationlistcontrollerimpl impl] 

error complains missing @inject-annotated constructor, exists! if replace implicit navigationlistcontrollerimpl instance creation (passing via @provides-method parameter) explicit (with new), dagger starts complaining same error presenter object second entry in same module, , on.

all situation looks strange, , i'd hear input more experienced dagger 2 users (and developers?).

thank in advance!

i got same error because forgot expose objects provided modules in parent component other components depend on it.

parent component example:

@singleton @component(modules = {appmodule.class}) public interface appcomponent {     apppref exposeapppref(); // issue caused forgot line, method name doesn't matter, matters object type apppref provided in appmodule want available in component declares component 1 of dependencies } 

sample component makes above component dependency

@userscope @component (dependencies = {appcomponent.class}) public interface activitycomponent {     void inject(mainactivity activity); } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -