In my module, in my base Application class
component = DaggerCompClassComponent.builder()
.classModule(new ModuleClass()).build();
There are some minor misconceptions/faults in your code above, here's a working implementation:
Application.java:
component = DaggerComponentClass.builder().classModule(new ModuleClass()).build();
The generated class will be named DaggerComponentClass
, not DaggerCompClassComponent
. If you can't run your app in Android Studio to get it built, try Build->Clean project and Build->Rebuild project in the menu. If everything is OK Dagger will have compiled DaggerComponentClass
which will be located in the same package as ComponentClass
.
ComponentClass.java:
@Component(modules = ModuleClass.class)
public interface ComponentClass {
void inject(AClassThatShouldGetInstancesInjected instance);
}
A Component in Dagger2 has methods named inject
that receive the instance to get instances injected into it, not the other way around. In the code above the class AClassThatShouldGetInstancesInjected
will typically call componentClass.inject(this);
to get instances injected into itself.
ModuleClass.java:
@Module
public class ModuleClass {
@Provides
@Singleton
public Interceptor provideInterceptor() {/*code*/}
//Your Providers...
}
The Module is correct in your code, make sure its annotated.