IllegalArgumentException: Parameter specified as non-null is null

In my case this error warned about probable passing a null as a parameter. Three ways of correction.

  1. Change a type of a parameter in corresponding place. If it is received from Java, add @NonNull annotation to a variable definition.
  2. Add !! to an argument of the method.
  3. Add ? 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).

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.


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.