I tried to use dagger 2 for the first time in one of my apps. Im getting error at dagger component class as the class did not get generated. please help me to get it work.
Link to my app https://github.com/kantigaricharan/Zolo
This the Error
02:45:55.663 [ERROR] [system.err] /Users/vamsikrishna/Downloads/Zolo/app/src/main/java/com/example/saicharan/zolo/dagger/component/AppComponent.java:17: error: com.example.saicharan.zolo.dashboard.DashboardInteractorImpl cannot be provided without an @Inject constructor or from an @Provides- or @Produces-annotated method.
02:45:55.663 [ERROR] [system.err] void inject(MyApp myApp);
02:45:55.663 [ERROR] [system.err] ^
02:45:55.663 [ERROR] [system.err] com.example.saicharan.zolo.dashboard.DashboardInteractorImpl is injected at
02:45:55.663 [ERROR] [system.err] com.example.saicharan.zolo.MyApp.dashboardInteractor
02:45:55.664 [ERROR] [system.err] com.example.saicharan.zolo.MyApp is injected at
02:45:55.664 [ERROR] [system.err] com.example.saicharan.zolo.dagger.component.AppComponent.inject(myApp)
02:45:55.722 [ERROR] [system.err] 1 error
This is my Component class in dagger
@Singleton @Component(modules = AppModule.class)
public interface AppComponent {
void inject(MyApp myApp);
void inject(DashboardInteractorImpl dashboardInteractorImpl);
}
This is module
@Module
public class AppModule {
private final MyApp myApp;
public AppModule(MyApp myApp){this.myApp=myApp;}
@Provides @Singleton
Context providesApplicationContext(){
return myApp;
}
@Provides @Singleton
SessionManagement getSession(Context context){
return new SessionManagement(myApp);
}
@Provides @Singleton
DatabaseHelper getDhelper(Context context){
return new DatabaseHelper(myApp);
}
}
Application class
public class MyApp extends Application {
protected AppComponent appComponent;
private static MyApp instance;
@Inject
DashboardInteractorImpl dashboardInteractor;
public static MyApp getInstance() {
return instance;
}
public static Context getContext(){
// return (MyApp) context.getApplicationContext();
return instance.getApplicationContext();
}
@Override
public void onCreate() {
instance = this;
super.onCreate();
appComponent = DaggerAppComponent
.builder()
.appModule(new AppModule(this))
.build();
appComponent.inject(this);
}
public AppComponent getAppComponent(){
return appComponent;
}
}
DasboardInteractorImpl
public class DashboardInteractorImpl implements DashboardInteractor {
private final DatabaseHelper dHelper;
private final SessionManagement sManager;
DashboardPresenterImpl mDashboardPresenter;
public DashboardInteractorImpl(DashboardPresenterImpl mDashboardPresenter){
this.mDashboardPresenter=mDashboardPresenter;
dHelper = new DatabaseHelper(MyApp.getContext());
sManager= new SessionManagement(MyApp.getContext());
}
//SOME LOGIC HERE..
}
Can i know what went wrong with my app?