FATAL EXCEPTION: main KotlinNullPointerException

后端 未结 4 462
悲哀的现实
悲哀的现实 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:16

    Your EditText is null. You can initialize your EditText. Example Kotlin code,

     override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_add_sales)
    
        val date = findViewById(R.id.editTextDate)
        date.apply {
            setText("15-11-2017")
            isEnabled = false
        }
      }
    

提交回复
热议问题