We Are Going To Discuss About Dagger 2: Cannot be provided without an @Provides-annotated method. So lets Start this Java Article.
Dagger 2: Cannot be provided without an @Provides-annotated method
- Dagger 2: Cannot be provided without an @Provides-annotated method
Your
CoffeeMachine
needsCoffeeMaker
. And you have declared that Dagger will take care of providing that dependency to theCoffeeMachine
by annotating the constructor with@Inject
. But Dagger says: - Cannot be provided without an @Provides-annotated method
Your
CoffeeMachine
needsCoffeeMaker
. And you have declared that Dagger will take care of providing that dependency to theCoffeeMachine
by annotating the constructor with@Inject
. But Dagger says:
Solution 1
Your CoffeeMachine
needs CoffeeMaker
. And you have declared that Dagger will take care of providing that dependency to the CoffeeMachine
by annotating the constructor with @Inject
. But Dagger says:
CoffeeMaker cannot be provided without an @Provides-annotated method
Because you haven’t specified anywhere how CoffeeMaker
object should be created. @Inject
ing SimpleMaker
is not enough, because SimpleMaker
!= CoffeeMaker
. So, you have to specify explicitly, that when Dagger wants CoffeeMaker
then provide him SimpleMaker
.
Change your module to this:
@Module
public class SimpleModule {
@Provides
Cooker providerCooker() {
return new Cooker("tom", "natie");
}
@Provides
CoffeeMaker provideCoffeeMaker(Cooker cooker) {
return new SimpleMaker(cooker);
}
}
Original Author azizbekian Of This Content
Conclusion
So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.