I am beginner at kotlin and I am trying to filter items which are present in one list, however i am using a loop and iterator for this purpose. I am getting mentioned exception in the if condition in
here . Can some one guide me where i am wrong.
I am pasting my function here .
fun getGateWays(
gateways: ArrayList<JsonObject>?,
callback: ResponseCallback<ArrayList<JsonObject>, String>
) {
getDistinctGateways(object : ResponseCallback<List<String>?, String>() {
override fun onFailure(failure: String) {
}
override fun onSuccess(response: List<String>?) {
for(e in gateways!!.iterator()){
if(e.get("value") in response){
gateways.remove(e)
}
}
callback.onSuccess(gateways!!)
}
})
}
You have to get a string value of each gateway in the list. You can do it with asString
method of JsonObject
:
if (e.get("value").asString in response!!) {
gateways.remove(e)
}
This is because
gateways.iterator() will give Iterator<JsonObject>
e is of JsonObject type and response is the type List<String>
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