kotlin 报错android.content.res.Resources$NotFoundException: String resource ID #0xc7

android kotlin 项目用Databinding 

app启动报错 

 Process: com.example.lanidemokt, PID: 25070                                                                         android.content.res.Resources$NotFoundException: String resource ID #0xc7                    at android.content.res.Resources.getText(Resources.java:348)                                                      at android.widget.TextView.setText(TextView.java:5831) 

原因: 

Resources$NotFoundException: String resource ID #0xc7 翻译过来是找不到字符串资源,

android:text="@{student.score}" 这里score是一个数字,不是字符串,需要转换

xml

  


 

MainActivity.kt

data class Student(var name: String = "LLL", var score: Int) : BaseObservable() //双击绑定响应式

    private fun initView() {
        binding?.msg?.setText("我是谁")
        login = Login("LANI", "我是谁")
        //  binding?.login = Login("LANI", "我是谁")
        //  这一步必须要,否则点击没反应,否则界面不显示对应的名字与信息
        binding?.setLogin(Login("LANI", "我是谁"))

        binding?.setStudent(Student("LEE", 199))

    }

解决:

通过拼接一个空串将数字类型转成字符串

 android:text="@{``+ student.score}"

运行ok

你可能感兴趣的:(android,kotlin,开发语言)