IllegalArgumentException: parameter specified as non-empty is null

I get 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 is 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()
}

The function call seems to be invalid. However, I do not know how to solve this problem. Is there something I missed?

+40
source share
4 answers

The exception is pretty clear: you pass nullfor the parameter.

By default, all variables and parameters in Kotlin are non-zero. If you want to pass a parameter to a nullmethod, you must add a type to it ?, for example:

fun fetchMerchantHashes(intent: Intent?)

: null-safety.

+83

. .

  1. . Java, @NonNull .
  2. !! .
  3. ? Kotlin. , Kotlin , Java (, @Nullable, @NonNull).
+1

Activity Java Kotlin Android Studio. , , override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent)

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?)

Difference in intent: Intent?

0
source

The simple answer will work for sure ... When you select data from the server using Rest Client (web service calls) (GET or POST) and if the json response can contain a parameter value of zero, you select the parameter and add it to the text view you get this error ..

Solution:   just add? mark the variable as shown below.

Example:

var batchNo: String? = "" (Correct Approach)
var batchNo= "" (Will Get Error)

Here I am trying to get a batch number using a service call.

0
source

All Articles