19

I have a subclass of Application that I am conforming to HasDispatchingActivityInjector, but when I try and run my app it will crash, saying:

Unable to start activity ComponentInfo{com.test.testing/com.test.testing.ui.main.MainActivity}: java.lang.RuntimeException: android.app.Application does not implement dagger.android.HasDispatchingActivityInjector

This is my Application subclass:

class MyApplication : Application(), HasDispatchingActivityInjector {

@Inject
lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Activity>

override fun onCreate() {
    super.onCreate()

    DaggerAppComponent.create().inject(this)
}

override fun activityInjector(): DispatchingAndroidInjector<Activity> {
    return dispatchingAndroidInjector
}

Has anyone else experienced this error before?

Thanks

Jordan
  • 1,213
  • 1
  • 9
  • 11

2 Answers2

78

It was because I hadn't added the android:name key with the value of my Application subclass to my manifest file.

Jordan
  • 1,213
  • 1
  • 9
  • 11
4

Add android:name=".MyApplication" in your manifest under application tag. Change the 'MyApplication' to the name of your application class