Я следую за Dagger2 образец TODO приложение, но имеет 2 ошибки.dagger2 не может найти символ
Ошибка1: не найден символ DaggerNetComponent
. (Который на самом деле есть)
Error2: Sharedpreference
не может быть обеспечен без @ поставщики аннотированного метода (который я думаю, что результаты Error1)
А вот мой длинный, но простой код:.
три модуля:
@Module
public class AppModule {
private final Application mApplication;
AppModule(Application application) {
mApplication = application;
}
@Provides
Application provideApplication() {
return mApplication;
}
}
@Module
public class LoadingModule {
public final LoadingContract.View mView;
public LoadingModule(LoadingContract.View mView) {
this.mView = mView;
}
@Provides
LoadingContract.View provideLoadingContractView() {
return mView;
}
}
@Module
public class NetModule {
@Provides @Singleton
SharedPreferences providesSharedPreferences(Application application) {
return PreferenceManager.getDefaultSharedPreferences(application);
}
}
И два компонента:
@Singleton
@Component(modules = {AppModule.class, NetModule.class})
public interface NetComponent {
}
@FragmentScoped
@Component(dependencies = NetComponent.class, modules = LoadingModule.class)
public interface LoadingComponent {
void inject(LoadingActivity loadingActivity);
}
я получаю NetComponent в MyApplication:
mNetComponent = DaggerNetComponent.builder()
.appModule(new AppModule(this))
.netModule(new NetModule())
.build();
и LoadingComponent в LoadingActivity:
DaggerLoadingComponent.builder()
.netComponent(((MyApplication)getApplication()).getNetComponent())
.loadingModule(new LoadingModule(loadingFragment))
.build()
.inject(this);
Единственное, что я хочу LoadingComponent
впрыснуть это LoadingPresenter
.
Также в LoadingActivity
:
@Inject LoadingPresenter mLoadingActivityP;
И это, как LoadingPresenter
построены:
public class LoadingPresenter implements LoadingContract.Presenter {
private SharedPreferences sharedPreferences;
private LoadingContract.View loadingView;
@Inject
public LoadingPresenter(LoadingContract.View loadingView, SharedPreferences sharedPreferences) {
this.loadingView = loadingView;
this.sharedPreferences = sharedPreferences;
}
@Inject
void setupListeners() {
loadingView.setPresenter(this);
}
public boolean checkLoginStatus() {
SharedPreferences.Editor editor = sharedPreferences.edit();
return sharedPreferences.getBoolean("loginStatus", false);
}
@Override
public void start() {
}
}
Конец моей программы.
Это раздражало меня в течение нескольких дней. Любая помощь приветствуется.
Я думаю, вам может потребоваться установить «общедоступную» доступность ко всем методам в ваших модулях. – Chisko
@Cheskos Я пробовал, но это не сработало. Спасибо, в любом случае. – Antelope
попробуйте очистить и перестроить ваш проект. Иногда помогает – Chisko