Why i get runtime error when try to return date

fun getBarTimeFromTouchLineInfo(lastTradedTime : Int, exchangeSegment : Int){
    val date = getBaseReferenceDate(exchangeSegment)
    date.seconds = date.seconds.plus(lastTradedTime)
    return Date(date.setMinutes(date.minutes.minus(1)))

error None of the following functions can be called with the arguments supplied. (Long) defined in java.util.Date (String!) defined in java.util.Date


What is the exact error message you are getting?


Don’t know if this answers the question, but kotlin doesn’t implicit convert numbers:



A few problems with your function:

  1. It doesn’t have a return type, so returning a date won’t compile either.
  2. This is the RuntimeError - date.setMinutes() returns void. There is no Date constructor which takes void as a parameter.
  3. All date modifier methods have been deprecated for many years. You should use a Calendar instead.

Here’s a version which should work for you:

fun getBarTimeFromTouchLineInfo(lastTradedTime : Int, exchangeSegment : Int): Date {
    val cal = Calendar.getInstance()
    cal.add(Calendar.SECOND, lastTradedTime)
    cal.add(Calendar.MINUTE, -1)
    return Date(cal.timeInMillis)


here we get error