प्रदान नहीं कर सकता मैं डैगर 2 के लिए बिल्कुल नया हूं और एक छोटी सी समस्या है। क्या आप मेरी मदद कर सकते हैं उम्मीद :) मेरे पास मेरी एंड्रॉयड परियोजनाडैगर 2 त्रुटि: बिना @ इंजेक्टर कन्स्ट्रक्टर
- अनुप्रयोग
- AppComponent
- AppModule
- MainActivity
- MainComponent
- MainModule
- IntentStarter में निम्नलिखित वर्गों
पुनर्निर्माण पर/संकलन मैं
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]
मैं वेरिएंट की लेकिन सफलता नहीं मिली बहुत कोशिश की ... मैं IntentStarter वर्ग .. में एक निर्माता के साथ इसे करने की कोशिश निर्माता के बिना ... त्रुटि मिलती है कुछ कोड ...
// 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();
}
}
...
0,123,// 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;
}
आपका प्रावधान तरीकों AppComponent से याद कर रहे हैं। – EpicPandaForce
आपका क्या मतलब है? मेरे AppComponent में मैं अपने ऐप मॉड्यूल को इंगित करता हूं और IntentStarter – Tobias
के लिए एक प्रदान विधि है, मैं वास्तव में डैगर 2 में नहीं हूं, लेकिन शायद यह मदद करता है? http://siphon9.net/loune/2015/04/dagger-2-0-android- माइग्रेशन-tips/ (अपनी त्रुटि खोजने के लिए नीचे देखें - अपने घटक के लिए 'प्रदान करेंन्टेंट स्टार्टर' विधि जोड़ने का प्रयास करें) उम्मीद है कि इससे मदद मिलती है । –