3

尝试使用 KotterKnife 时出现以下错误 - 但仅适用于某些课程。这是怎么回事?

e: /Users/user/dev/git/to14/android/src/main/kotlin/com.example/adapters/ChapterListAdapter.kt: (59, 34): Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
public fun <T : android.view.View> android.app.Dialog.bindView(id: kotlin.Int): kotlin.properties.ReadOnlyProperty<kotlin.Any, android.widget.TextView> defined in butterknife
public fun <T : android.view.View> android.support.v4.app.Fragment.bindView(id: kotlin.Int): kotlin.properties.ReadOnlyProperty<kotlin.Any, android.widget.TextView> defined in butterknife
public fun <T : android.view.View> android.app.Fragment.bindView(id: kotlin.Int): kotlin.properties.ReadOnlyProperty<kotlin.Any, android.widget.TextView> defined in butterknife
public fun <T : android.view.View> android.view.ViewGroup.bindView(id: kotlin.Int): kotlin.properties.ReadOnlyProperty<kotlin.Any, android.widget.TextView> defined in butterknife
public fun <T : android.view.View> android.support.v7.widget.RecyclerView.ViewHolder.bindView(id: kotlin.Int): kotlin.properties.ReadOnlyProperty<kotlin.Any, android.widget.TextView> defined in butterknife
public fun <T : android.view.View> android.app.Activity.bindView(id: kotlin.Int): kotlin.properties.ReadOnlyProperty<kotlin.Any, android.widget.TextView> defined in butterknife
4

1 回答 1

5

Kotterknife 的委托仅bindView适用于、、、、、支持库和回收器视图的子类。我猜您正在尝试将 view 绑定为 的属性,但要使其正常工作,您必须拥有可以调用的对象。ActivityDialogViewGroupFragmentFragmentViewHolderListAdapterfindViewById

对于非 RecyclerViewViewHolder你可以试试

class ViewHolder(view: View) { 
    val textView: TextView = view.findViewById(R.id.name) as TextView 
}
于 2015-02-26T19:32:51.543 回答