2016-06-22 2 views
0

私は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() { 
    } 
} 


終了。
数日間私を迷惑にしています。どんな助けもありがとうございます。

+0

あなたのモジュール内のすべてのメソッドに 'public'アクセス可能性を設定する必要があるかもしれないと思います。 – Chisko

+0

@Cheskos試しましたが、うまくいかなかった。とにかくありがとう。 – Antelope

+0

プロジェクトのクリーニングと再構築を試してください。時々役に立ちます – Chisko

答えて

4

あなたはエラーの原因を後方に持っています。 Dagger*クラスは、注釈プロセッサの最終出力です。グラフにエラーがあり、Daggerプロセッサが完了できなかったため、出力が欠落していました。

2番目のエラーは、バインドされていないコンポーネント内からSharedPreferencesを要求しているというエラーです。サブコンポーネントではなくコンポーネントの依存関係を選択したため、依存関係のすべてのバインドはに継承されませんLoadingComponentNetComponentからのバインディングを使用するには、それらをコンポーネントインタフェースで公開する必要があります。 SharedPreferences sharedPreferences();NetComponentに追加するか、サブコンポーネントに切り替えて問題を解決する必要があります。

詳細については、@Component docsおよびpage on subcomponents in the user's guideを参照してください。

+0

ありがとう!しかし別の問題があります...あなたが忙しくないなら、あなたはhttp://stackoverflow.com/questions/37981293/dagger2-gc-overhead-limit-exceededをチェックできますか? – Antelope

関連する問題