I'm getting the following 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)
Here's 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()
}
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?
The exception is pretty clear: you're passing null
for the parameter.
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?)
For more information: null-safety.
In my case this error warned about probable passing a null as a parameter. Three ways of correction.
@NonNull
annotation to a variable definition.!!
to an argument of the method.?
to the parameter in Kotlin class. I think, Kotlin conversion tool might do this by default, if in Java class there were no annotations used (like @Nullable
, @NonNull
).Simple Answer Will Work For Sure... When you are fetching the data from the Server using Rest Client (Web Services calls) (GET Or POST) and if there could be a null parameter value in the json response, and you are fetching the parameter and appending it to textview you get this error..
Solution: just append ? mark to the variable as below..
Example:
var batchNo: String? = "" (Correct Approach)
var batchNo= "" (Will Get Error)
Here I am trying to fetch batchNo using service call.
I caught similar exception after converting an Activity from Java to Kotlin using Android Studio converting tool. So, it's that I got override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent)
It's right override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?)
Difference in intent: Intent?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With