olmadan sağlanamaz. Dagger 2 için tamamen yeni ve küçük bir sorunum var. bana yardım edebilir umut :) Ben benim android projesiHançer2 hatası: @Inject constructor
- App
- AppComponent
- AppModule
- MainActivity
- MainComponent
- MainModule
- IntentStarter aşağıdaki sınıfları
yeniden inşa At/derleme i ben ... yapıcı olmayan IntentStarter sınıfında .. kurucular ile denedim ... varyantların ancak başarılı olamadı çok çalıştı
Error:(15, 10) error: xyz.IntentStarter cannot be provided without an @Inject constructor or from an @Provides- or @Produces-annotated method.
xyz..MainActivity.intentStarter
[injected field of type: xyz..IntentStarter intentStarter]
hatayı olsun kodlar ...
// AppComponent.class
@Singleton
@Component(modules = {AppModule.class})
public interface AppComponent {
// Empty...
}
...
// AppModule.class
@Singleton
@Module
public class AppModule {
Application application;
Context context;
public AppModule(Application app) {
this.application = app;
this.context = app.getApplicationContext();
}
@Provides
public Application provideApplication() {
return application;
}
@Provides
public Context provideContext() {
return context;
}
@Provides
public EventBus provideEventBus() {
return EventBus.getDefault();
}
@Provides
public IntentStarter provideIntentStarter() {
return new IntentStarter();
}
}
...
// App.class
public class App extends Application {
public AppComponent appComponent;
public AppComponent getAppComponent() {
return appComponent;
}
@Override
public void onCreate() {
super.onCreate();
appComponent = DaggerAppComponent.builder()
.appModule(new AppModule(this))
.build();
}
}
...
//MainAcitivty.class
public class MainActivity extends MosbyActivity {
@Inject
IntentStarter intentStarter;
MainActivityComponent component;
@Override
protected void injectDependencies() {
component = DaggerMainActivityComponent.builder()
.appComponent(((App) getApplication()).getAppComponent())
.build();
component.inject(this);
}
}
...
//MainActivityComponent.class
@ActivityScope
@Component(dependencies = {AppComponent.class})
public interface MainActivityComponent {
void inject(MainActivity mainActivity);
}
...
// MainActivityModule
@Module
public class MainActivityModule {
}
...
//IntentStarter
public class IntentStarter {
@Inject
Context context;
}
Kişisel hüküm yöntemleri AppComponent eksik, belirli olması. – EpicPandaForce
Ne demek istiyorsun? Benim AppComponent benim AppModule için işaret ve IntentStarter – Tobias
için bir yöntem var gerçekten Hançer 2 içine değilim, ama belki bu yardımcı olur? http://siphon9.net/loune/2015/04/dagger-2-0-android-migration-tips/ (Hatanızı bulmak için aşağıya bakın - bileşeninize bir 'offerIntentStarter 'yöntemi eklemeyi deneyin) . –