Android Kotlin:无法覆盖?
Android Kotlin: Override not possible?
我想发送一个关于 volley 的 HTTP post。根据IDE,我无法覆盖getBodyContentType 和getBody 方法,网上的一些示例是否显示了这一点。它的语法(大括号)是什么?我做错了什么?
error message: Modifier 'override' is not applicable to 'local
function'
val textView = findViewById<TextView>(R.id.loginStatus)
val queue = Volley.newRequestQueue(this)
val url = "http://example.com/v1/user/read"
val stringRequest = StringRequest( Request.Method.GET, url,
Response.Listener<String> { response ->
textView.text = "Response is here"
},
Response.ErrorListener { textView.text = "Error." }
){
override fun getBodyContentType(): String {
return "application/json"
}
override fun getBody(): ByteArray {
return "{\"email\":\"123@foo.de\", \"passwort\":\"123\"}".toString().toByteArray()
}
}
在 Kotlin 中也可以实现同样的效果
val stringRequest = object : StringRequest(...){
override fun getBodyContentType(): String {
...
}
override fun getBody(): ByteArray {
...
}
}
我想发送一个关于 volley 的 HTTP post。根据IDE,我无法覆盖getBodyContentType 和getBody 方法,网上的一些示例是否显示了这一点。它的语法(大括号)是什么?我做错了什么?
error message: Modifier 'override' is not applicable to 'local function'
val textView = findViewById<TextView>(R.id.loginStatus)
val queue = Volley.newRequestQueue(this)
val url = "http://example.com/v1/user/read"
val stringRequest = StringRequest( Request.Method.GET, url,
Response.Listener<String> { response ->
textView.text = "Response is here"
},
Response.ErrorListener { textView.text = "Error." }
){
override fun getBodyContentType(): String {
return "application/json"
}
override fun getBody(): ByteArray {
return "{\"email\":\"123@foo.de\", \"passwort\":\"123\"}".toString().toByteArray()
}
}
val stringRequest = object : StringRequest(...){
override fun getBodyContentType(): String {
...
}
override fun getBody(): ByteArray {
...
}
}