我得到了以下runtime error个:

 checkParameterIsNotNull, parameter oneClickTokens
    at com.info.app.fragments.Fragment_Payment_Profile$fetchMerchantHashes$1.onPostExecute(Fragment_Payment_Profile.kt:0)
    at com.info.app.fragments.Fragment_Payment_Profile$fetchMerchantHashes$1.onPostExecute(Fragment_Payment_Profile.kt:1543)

以下是my code:

 private fun fetchMerchantHashes(intent: Intent) {
    // now make the api call.
    val postParams = "merchant_key=$key&user_credentials=$var1"
    val baseActivityIntent = intent
    object : AsyncTask<Void, Void, HashMap<String, String>>() {

        override fun doInBackground(vararg params: Void): HashMap<String, String>? {
                ...
        }

        override fun onPostExecute(oneClickTokens: HashMap<String, String>) {
            super.onPostExecute(oneClickTokens)
            ...

        }
    }.execute()
}

函数调用似乎无效.然而,我不知道如何解决这个问题.我有没有错过什么关于Kotlin 的事?

推荐答案

The exception is pretty clear: you're passing null for the parameter.

默认情况下,Kotlin中的所有变量和参数都是非空的.如果要向该方法传递null个参数,则应在其类型上添加?,例如:

fun fetchMerchantHashes(intent: Intent?)

For more information: null-safety.

Kotlin相关问答推荐

Lambda和普通Kotlin函数有什么区别?

Fleet无法从构建文件自动重新加载更改错误'

如何访问方法引用的接收者?

在 Kotlin 中,为什么我们要在闭包中捕获值

如何将消费者放入 Kotlin 的 map 中?

为什么 Kotlin 在将协变类型参数转换为不变类型参数时会产生 Unchecked Cast 警告?

kotlin 父类具有依赖于抽象变量的变量

我可以在 Kotlin 中使用接口类型作为构造函数参数吗

Kotlin 类的调用方法

在 Kotlin 中实现 (/inherit/~extend) 注解

更新到版本4.10.1/4.10.2后 Gradle 同步失败

未在IntelliJ IDEA上运行临时文件

Kapt不适用于Android Studio 3.0中的AutoValue

用mockk验证属性设置程序吗?

如何暂停kotlin coroutine直到收到通知

如何在协程之外获取 Flow 的值?

Kotlin扩展函数与成员函数?

将字符串转换为HashMap的最简单方法

访问Kotlin中的属性委托

Kotlin for assertThat(foo, instanceOf(Bar.class))