指定为非空的参数

指定为非空的参数

本文介绍了IllegalArgumentException:指定为非空的参数为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下运行时错误:

 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)

这是我的代码:

 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 特定内容吗?

It seems that the function call seems to be invalid. However, I don't know how to fix this problem. Is there anything Kotlin specific I've missed?

推荐答案

异常很明显:您正在为参数传递 null.

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

默认情况下,Kotlin 中的所有变量和参数都是非空的.如果您想将 null 参数传递给方法,您应该将 ? 添加到它的类型中,例如:

By default all variables and parameters in Kotlin are non-null. If you want to pass null parameter to the method you should add ? to it's type, for example:

fun fetchMerchantHashes(intent: Intent?)

更多信息:null-safety.

这篇关于IllegalArgumentException:指定为非空的参数为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 06:39