私はDagger2サンプルTODOのサンプルに続いていますが、2つのエラーが発生しました。dagger2が記号を見つけることができません
エラー1:シンボルDaggerNetComponent
が見つかりません。 (私はERROR1からの結果を考えている)Sharedpreference
は、@プロバイダアノテーション付きメソッドなしで提供することができません
そして、ここで私の長いが、簡単なコードです::。
誤差2(どちらが実際にある)
三個のモジュール:
@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);
}
}
2つの成分:
@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);
}
私はMyApplicationという中でNetComponentを取得する:
mNetComponent = DaggerNetComponent.builder()
.appModule(new AppModule(this))
.netModule(new NetModule())
.build();
とLoadingActivityでLoadingComponent:
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() {
}
}
終了。
数日間私を迷惑にしています。どんな助けもありがとうございます。
あなたのモジュール内のすべてのメソッドに 'public'アクセス可能性を設定する必要があるかもしれないと思います。 – Chisko
@Cheskos試しましたが、うまくいかなかった。とにかくありがとう。 – Antelope
プロジェクトのクリーニングと再構築を試してください。時々役に立ちます – Chisko