Kotlin 布局视图未使用Butterknife初始化

Kotlin 布局视图未使用Butterknife初始化,kotlin,butterknife,Kotlin,Butterknife,在以下代码中: class LobbyFragment : Fragment() { @Inject lateinit var lobbyFragmentHelloService: LobbyFragmentHelloService @BindView(R.id.lobby_fragment_hello) lateinit var lobbyFragmentHelloTextView: TextView lateinit var unbinder:

在以下代码中:

class LobbyFragment : Fragment() {

    @Inject
    lateinit var lobbyFragmentHelloService: LobbyFragmentHelloService

    @BindView(R.id.lobby_fragment_hello)
    lateinit var lobbyFragmentHelloTextView: TextView

    lateinit var unbinder: Unbinder

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val view = inflater.inflate(R.layout.lobby_fragment, container, false)
        unbinder = ButterKnife.bind(this, view)
        return view
    }

    override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        sayFragmentHello()
    }

    override fun onAttach(context: Context?) {
        AndroidInjection.inject(this)
        super.onAttach(context)
    }

    override fun onDestroyView() {
        super.onDestroyView()
        unbinder.unbind()
    }

    private fun sayFragmentHello() {
        lobbyFragmentHelloTextView.text = lobbyFragmentHelloService.sayHello()
    }
}

lobbyFragmentHelloTextView从未初始化。Butterknife用于初始化此变量。为什么不被SayFrimaTeNeo的时间初始化?

< P>我不确定到底出了什么毛病,但要解决这个问题,你可以考虑使用KTILIN内置的合成绑定,然后去掉折刀。效率更高


我不确定到底出了什么毛病,但要解决这个问题,你可以考虑用合成装订的KTILLIN去掉奶油刀。效率更高


您很可能缺少
应用插件:“kotlin kapt”
。否。这显然是一个棘手的问题。我把它拿走了。Butterknife在Kotlin中是无用的。你的Butterknife版本是什么?你很可能缺少应用插件:'Kotlin kapt'。否。这显然是一个棘手的问题。我把它拿走了。在Kotlin,Butterknife是无用的。你的Butterknife版本是什么?就在你发布答案之前,我做了,这就解决了问题。老实说,我从一个示例应用程序中获取了该代码。这正好证实了我的观点,即开发人员已经变得如此依赖于像Butterknife这样荒谬的第三方库,最终只需要花费数小时来解决问题。就在你发布答案之前,我这样做了,解决了问题。老实说,我从一个示例应用程序中获取了该代码。这正好证实了我的观点,即开发人员已经变得如此依赖于像Butterknife这样荒谬的第三方库,最终只需要花费数小时来解决问题。