Kotlin 错误:无法使用提供的参数调用以下任何函数

时间:2021-05-25 07:24:50

标签: android kotlin

以下是编译错误

None of the following functions can be called with the arguments supplied: 
public final operator fun div(other: Byte): Int defined in kotlin.Int
public final operator fun div(other: Double): Double defined in kotlin.Int
public final operator fun div(other: Float): Float defined in kotlin.Int
public final operator fun div(other: Int): Int defined in kotlin.Int
public final operator fun div(other: Long): Long defined in kotlin.Int
public final operator fun div(other: Short): Int defined in kotlin.Int

我在我的活动中尝试使用倒数计时器,下面是我的代码。我在除法运算符上得到了错误标记

mTimerTextview.setText(millisUntilFinished.toInt()  / 1000.toString() + "s")

完整代码

startQuizButton.setOnClickListener {
            constraintChild.visibility = View.VISIBLE
            startQuizButton.visibility = View.GONE
            score = 0
            totalAttempt = 0
            mStatusTextview.text = "0/0"
            newQuestion()
            countDownTimer = object : CountDownTimer(30100, 1000) {
                override fun onTick(millisUntilFinished: Long) {
                    mTimerTextview.setText(millisUntilFinished.toInt()  / 1000.toString() + "s")
                }

1 个答案:

答案 0 :(得分:0)

我只是替换了这个:

val one = millisUntilFinished.toInt()
                    val two = 1000
                    mTimerTextview.text = ((one / two).toString() + "s")