Answer the question
In order to leave comments, you need to log in
Why is the Dagger component not created when writing the interface in Kotlin?
Practicing using Dagger 2 in Android.
Tagged one of the snippets with @Inject
class PreviewMediaFragment @Inject constructor() : Fragment() {
......
}
@Component
public interface AppComponent {
public PreviewMediaFragment getFragment();
}
class BaseApplication : Application() {
lateinit var appcomponent: AppComponent
override fun onCreate() {
super.onCreate()
appcomponent = DaggerAppComponent.create()
}
}
@Component
interface AppComponent {
fun getFragment():PreviewMediaFragment
}
Answer the question
In order to leave comments, you need to log in
To generate the code, you need to run kapt .
Not relevant to the question, but injecting a fragment constructor is a very bad idea. The fragment constructor should be empty, and therefore it is easier to call it by hand.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question