I try to send different types of post parameters in api but it did not work correctly. Any idea why?
Here is my code.
Firstly I wrap my parameters in a simple container and pass that as a parameter to AsyncTask, like this:
class MyParams {
var paramName: String = ""
var paramaddress: String = ""
var paramlatitude: Float = 0.toFloat()
var paramlongitude: Float = 0.toFloat()
constructor(funName: String, funAddress: String, funLatitude: Float, funLongitude: Float) {
this.paramName = funName
this.paramaddress = funAddress
this.paramlatitude = funLatitude
this.paramlongitude = funLongitude
}
}
class myClass : AsyncTask<MyParams, Void, String>() {
override fun onPreExecute() {
super.onPreExecute()
}
override fun onPostExecute(httpResponseMsg: String) {
super.onPostExecute(httpResponseMsg)
...
}
override fun doInBackground(vararg params: MyParams): String {
var name = params[0].paramName
var address = params[0].paramaddress
var latuitude = params[0].paramlatitude
var longitude = params[0].paramlongitude
hashMap["name"] = name
hashMap["address"] = address
hashMap["latuitude"] = latuitude
hashMap["longitude"] = longitude
finalResult = httpParse.postRequest(hashMap, HttpURL)
println("responseeeeeeeee-----="+finalResult)
return finalResult
}
}
val params = MyParams(funName,funAddress,funLatitude,funLongitude)
val myTask = myClass()
myTask.execute(params)
But in this line hashMap["name"] = name
I got the following error:
Type inference failed: Cannot infer type parameter V in inline operator fun MutableMap.set(key: K, value: V): Unit None of the following substitutions receiver: MutableMap arguments: (String,Params) receiver: MutableMap arguments: (String,String) can be applied to receiver: HashMap arguments: (String,String)
hashMap
defined? - user2340612