【发布时间】:2020-02-19 10:48:04
【问题描述】:
我在 Kotlin 中编程,我有 Date 类的扩展功能。
fun Date.toString(format: String, locale: Locale = Locale.getDefault()): String {
val formatter = SimpleDateFormat(format, locale)
return formatter.format(this)
}
它在onCreate 中运行良好,但在Async task 中的doInBackground 内部却给了我错误
我在doInBackground里面有这些行
val currentDateTime = MainActivity().getCurrentDateTime()
val timeIs = currentDateTime.toString("HH:mm:ss")
getCurrentDateTime() 返回Date 类的实例
toString() is 中的参数给出错误
toString():String 在 java.util.Date 中定义的公共开放乐趣的参数太可能了
我认为它正在尝试在这里应用 Java,例如 Date.toString()。
但是我应该怎么解决呢?
【问题讨论】:
-
它是如何调用的?
-
@Aivaras 我已经更新了问题,请检查