【问题标题】:java.lang.reflect.InvocationTargetException (no error message) for provide adapters提供适配器的 java.lang.reflect.InvocationTargetException(无错误消息)
【发布时间】:2022-01-14 03:35:26
【问题描述】:

我使用自己的自定义适配器类,但是当我想提供它们时,我遇到了问题,我不明白为什么!

@Module
abstract class AppointmentListModule {

    companion object {
        @Provides
        @PerChildFragment
        fun adapter(appExecutors: AppExecutors): SingleDataAdapter<AppointmentDigestData> = SingleDataAdapter(
            appExecutors,
            R.layout.item_appointment_patient,
            SimpleDiffCallback(AppointmentDigestData::id),
            BR.item
        )
    }
}

这是我收到的错误:

error: @Provides methods can only be present within a @Module or @ProducerModule
        public final ir.logicfan.core.ui.recyclerview.adapter.SingleDataAdapter<com.ennings.data.entity.patient.AppointmentDigestData> adapter(@org.jetbrains.annotations.NotNull()

SingleDataAdapter 构造函数:

open class SingleDataAdapter<T>(
    appExecutors: AppExecutors,
    @LayoutRes protected val itemLayout: Int,
    diffCallback: DiffUtil.ItemCallback<T>,
    private val bindingItemVariableId: Int,
    private val positionBindingVariableId: Int? = null
) : ListAdapter<T, DataBindingViewHolder<T>>(
    AsyncDifferConfig.Builder<T>(diffCallback)
        .setBackgroundThreadExecutor(appExecutors.diskIO())
        .build()
) {....}

有人有想法吗?

【问题讨论】:

  • 你用的是什么版本的 Dagger?

标签: android kotlin gradle dagger-2


【解决方案1】:

我现在无法检查它,但正如 here 所说,尝试将 @JvmStatic 添加到有趣的适配器(appExecutors:AppExecutors)函数中。如果可以,请显示 SingleDataAdapter 构造函数

【讨论】:

  • 问题正文已编辑!
猜你喜欢
  • 2021-04-30
  • 2021-08-21
  • 2020-12-18
  • 1970-01-01
  • 1970-01-01
  • 2013-05-05
  • 1970-01-01
  • 1970-01-01
  • 2019-05-17
相关资源
最近更新 更多