这是代码。如您所见,MainActivity中有一个字段dataBus
。
private lateinit var dataBus: LiveDataBus
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
dataBus = ViewModelProviders.of(this).get(LiveDataBus::class.java)
val nameObserver = Observer<String> {
nameTextView.text = it
}
dataBus.currentName.observe(this, nameObserver)
change_content.setOnClickListener {
dataBus.currentName.value = nameTextView.text.toString() + "Jack"
}
}
我将break point
放在了clickListener
中。然后我在AndroidStudio中评估表达式dataBus
,但是出现异常。
java.lang.NoSuchFieldError:找不到字段:MemberDescription(ownerInternalName = com / example / livedatabus / MainActivity,name = dataBus,desc = Lcom / example / livedatabus / LiveDataBus; isStatic = false)