Reputation: 171
//MODULES
@Module
public class PresenterModule {
@Provides
@PerActivity
public MainPresenter provideMainPresenter() {
return new MainPresenter();
}
@Provides
@PerActivity
public PreLoginPresenter providePreLoginPresenter() {
return new PreLoginPresenter();
}
@Provides
@PerActivity
public NotificationPresenter provideNotificationPresenter() {
return new NotificationPresenter();
}
}
@Module
public class UserLoginModule {
@Provides
@PerActivity
public UserModel getUser(){
return new UserModel();
}
}
//COMPONENTS
@PerActivity
@Component(modules = {UserLoginModule.class})
public interface UserLoginComponent {
void injectSharedPreferences(SharedPreferences sharedPreferences);
void injectPreLoginPresenter(PreLoginActivity preLoginActivity);
}
@PerActivity
@Component(modules = {PresenterModule.class})
public interface PresenterComponent {
//void injectMainPresenter(MainActivity mainActivity);
void injectPreLoginPresenter(PreLoginActivity preLoginActivity);
//void injectNotificationPresenter(NotificationActivity notificationActivity);
}
` //PRELOGINPRESENTER
public class PreLoginPresenter {
@Inject
UserModel userModel;
public String onStateSelected(String state) {
userModel.setState(state);
return userModel.getState();
}
}
//PRELOGINACTIVITY`
//INSIDE THE ONCREATE
//Instantiate dagger 2
PresenterComponent presenterComponent = DaggerPresenterComponent.builder()
.build();
presenterComponent.injectPreLoginPresenter(PreLoginActivity.this);//passar o contexto para o componente
//Instantiate dagger 2
UserLoginComponent userLoginComponent = DaggerUserLoginComponent.builder()
.build();
userLoginComponent.injectPreLoginPresenter(PreLoginActivity.this);//passar o contexto para o componente``
//ERROR LOG
Error:(18, 53) error: cannot find symbol class DaggerPresenterComponent Error:(19, 53) error: cannot find symbol class DaggerUserLoginComponent Error:(19, 10) error: gorick.gradesprojectandroid.MVP.Presenter.Presenters.PreLoginPresenter cannot be provided without an @Inject constructor or from an @Provides- or @Produces-annotated method. This type supports members injection but cannot be implicitly provided. gorick.gradesprojectandroid.MVP.Presenter.Presenters.PreLoginPresenter is injected at gorick.gradesprojectandroid.MVP.View.PreLoginActivity.preLoginPresenter gorick.gradesprojectandroid.MVP.View.PreLoginActivity is injected at gorick.gradesprojectandroid.Dagger2.Component.UserLoginComponent.injectPreLoginPresenter(preLoginActivity)
Upvotes: 0
Views: 1404
Reputation: 95614
You've bound your PreLoginPresenter in your PresenterModule, but you haven't installed it in your UserLoginComponent. This means that your UserLoginComponent doesn't have the bindings it needs to inject PreLoginPresenter into PreLoginActivity, so the code generation fails and it gives you that error message.
You shouldn't ever need to inject the same class with two different Components; there's no way to express that one component satisfies certain bindings and another component satisfies others. Instead, make sure you have one component that covers everything, and inject using that.
Upvotes: 2