Android kotlin - upload image with Volley error: Accidental override: The following declarations have the same JVM signature

Android kotlin - upload image with Volley error: Accidental override: The following declarations have the same JVM signature

fun UploadToServer(klein: Bitmap, mitte: Bitmap){

        val baos = ByteArrayOutputStream()
        klein.compress(Bitmap.CompressFormat.JPEG, 90, baos)
        val imageBytes = baos.toByteArray()
        val imageString = Base64.encodeToString(imageBytes, Base64.DEFAULT)


        val request = object:StringRequest(Request.Method.POST, "http://www.xxxx.com/uploadimage.php", object: Response.Listener<String> {
            override fun onResponse(response: String) {
                // Display the first 500 characters of the response string.
                Log.d("letsSee", "Success! JSON: " + response)
            }
        }, object: Response.ErrorListener {
            override fun onErrorResponse(volleyError:VolleyError) {
                Toast.makeText(this@UploadImage, "Some error occurred -> " + volleyError, Toast.LENGTH_LONG).show()
            }
        }) {
            protected val params:Map<String, String>

                @Throws(AuthFailureError::class)
                get() {
                    val parameters = HashMap<String, String>()
                    parameters.put("klein", imageString)
                    return parameters
                }

        }
        val rQueue = Volley.newRequestQueue(this@UploadImage)
        rQueue.add(request)

    }

这是什么,我需要在这里做什么?我开始后悔使用 Kotlin,尽管 Java 简直令人作呕。提前致谢

将 val 关键字后的 params 更改为 parameter kotlin 自动为变量创建 get 方法并且您声明了 params,因此 getter 方法将是 getParams,这与预定义的方法冲突。

改用这个:

override fun getParams(): MutableMap<String, String> {
    val parameters = HashMap<String, String>()
    parameters.put("klein", imageString)
    return parameters
}

Kotlin有两种形式的Map对象:Map和MutableMap。 MutableMap等于Java的Map,而Map是Kotlin自己的东西