Reputation: 2864
I'm working on an Android application which has dagger dependencies. When injecting class through constructor injection it's throwing an error that it cannot find symbol. If I provide the dependency through an @Provides
method defined inside a module, everything works fine.
The code:
public class SixthGenericTest {
@Inject
FirstTest firstTest;
@Inject
public SixthGenericTest()
{
Injection.create().getAppComponent().inject(this);
}
public String getData(){
return firstTest.getTestName();
}
}
@Singleton
@Component(modules = {FirstModule.class})
public interface AppComponent {
void inject(SixthGenericTest sixthGenericTest);
}
and the error I got:
Error:(19, 28) error: cannot find symbol method injectMembers(MembersInjector,SixthGenericTest)
Upvotes: 2
Views: 4687
Reputation: 22394
Upgrade your dagger version
dependencies {
compile 'com.google.dagger:dagger:2.x'
annotationProcessor 'com.google.dagger:dagger-compiler:2.x'
}
Upvotes: 5
Reputation: 4737
You don't need to injectInjection.create().getAppComponent().inject(this);
@Inject
annotated constructeur is enough since it is automatically added to the graph, you may though add your scope above your class name
@Singleton
public class SixthGenericTest {
FirstTest firstTest;
@Inject
public SixthGenericTest( FirstTest firstTest )
{
this.firstTest = firstTest;
}
public String getData()
{
return firstTest.getTestName();
}
}
and remove from component:
void inject(SixthGenericTest sixthGenericTest);
Upvotes: -2