My app crashes as soon as I click on OK after selecting the date

This is the code that I used in kotlin and it is running fine but the app crashes as soon as I click ok after selecting the Date of Birth. The app worked fine till displaying just the date but it is crashing as soon as I used the minutes

fun Calendara(){

    val Mycalendar= Calendar.getInstance()
    val Year=Mycalendar.get(Calendar.YEAR)
    val month=Mycalendar.get(Calendar.MONTH)
    val DayOfMonth=Mycalendar.get(Calendar.DAY_OF_MONTH)
    var dpd=DatePickerDialog(this,
        DatePickerDialog.OnDateSetListener { _, year, Month, dayOfMonth ->
           Toast.makeText(this,"$DayOfMonth-$month-$Year",Toast.LENGTH_LONG).show()
            val selectedDate="$DayOfMonth/${month+1}/$Year"
            datet?.text=selectedDate

            val sdf=SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH)
             val thedate=sdf.parse(selectedDate?.toString())

             val thedateinMinutes = thedate.time / 60000

            val currentdate = System.currentTimeMillis() / 60000

            val difference = currentdate - thedateinMinutes


            minutes?.text = difference.toString()

                                           },
        Year,
        month,
        DayOfMonth
    )
    dpd.datePicker.maxDate=System.currentTimeMillis()-8640000
     dpd.show()

   }

}

Above is the code and below is the errow which is displayed when I run through the debugger

Error: enter image description here

The output should display the date we selected and your age in minutes



Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)