> cannot be provided without an @Provides-annotated method

前端 未结 1 1448
伪装坚强ぢ
伪装坚强ぢ 2021-01-13 09:15

I am trying to create a viewmodel module like in this example but I am having this error

error: java.util.Map,javax.inject.Provider> cannot be provid

1条回答
  •  清酒与你
    2021-01-13 09:38

    You need to bind your view models using Dagger multibindings. In other words, bind your view models and annotate them with the @IntoMap multibinding annotation. In the same example you posted, you can find an example of it here. In the example, they created the ViewModelKey annotation in order to specify the key from which Dagger can retrieve your view model from the map (usually the view model's class). Dagger will create the map at compile time, and that's why you get the error - if you don't specify any view model to be part of the map, Dagger can't know which types it should instantiate.

    0 讨论(0)
提交回复
热议问题