I used dagger2 in my project, but the injection field is always null. Here is the code.
sorry, my english is poor. Thanks in advance.
Module
@Module
public class RetrofitModule {
@Provides
@Singleton
Retrofit provideRetrofit() {
return new Retrofit.Builder().build();
}
}
Component
@Component(modules = RetrofitModule.class)
public interface RetrofitComponent {
void inject(Activity activity);
}
And in MainActivity, I write this
DaggerRetrofitComponent.builder().build().inject(this);
But the Retrofit is always null. How can I solve it?
inject()? - EgorRetrofitModulewhen creating the component, you should be calling.retrofitModule(new RetrofitModule()). - Egor