FATAL EXCEPTION: main KotlinNullPointerException

后端 未结 4 518
悲哀的现实
悲哀的现实 2021-01-20 10:46

This is my first time building an android application. However when i run the app on my Virtual Device, it stopped working and keeps crashing. The error says something about

4条回答
  •  遇见更好的自我
    2021-01-20 11:00

    It seems like you forgot to initialize date editText. Why not to try Kotlin Android Extension plugin. By using this plugin you don't need to initialize the views instead you can directly use them using their id. For your case: Just add import

    import kotlinx.android.synthetic.main.activity_add_sales.*
    

    Then you can now remove your:

    val date: EditText? = null
    val changeDate: CheckBox? = null
    val yes: RadioButton? = null
    val no: RadioButton? = null
    

    and you can access them by their ids. like

    date.setText("15-11-2017")
    

提交回复
热议问题