Home > OS >  Type mismatch. Required: String! Found: Int error
Type mismatch. Required: String! Found: Int error

Time:08-16

I'm trying to GET request, but I'm getting error on line 4 in the code below

    val queue = Volley.newRequestQueue(this)
    val url = "https://meme-api.herokuapp.com/gimme"
    val jsonObjectRequest = JsonObjectRequest(
        Request.Method.GET, null,
        Response.Listener { response ->
            val url = response.getString("url")
        },
        Response.ErrorListener {
            Toast.makeText(this,"something wrong", Toast.LENGTH_LONG).show()
        })
        queue.add(jsonObjectRequest)

CodePudding user response:

You havent passed url to request.

val queue = Volley.newRequestQueue(this)
val url = "https://meme-api.herokuapp.com/gimme"
val jsonObjectRequest = JsonObjectRequest(
    Request.Method.GET, url, null, //You need to pass url here
    Response.Listener { response ->
        val url = response.getString("url")
    },
    Response.ErrorListener {
        Toast.makeText(this,"something wrong", Toast.LENGTH_LONG).show()
    })
    queue.add(jsonObjectRequest)
  • Related