Search code examples
androidretrofit2

Type mismatch: inferred type is <no name provided> but Callback<Post!>! was expected


I have the function

        val client = NetworkService()
        val call = client.getService().getAllPost()
        call.enqueue(object : Callback<ArrayList<Post>>{
            override fun onFailure(call: Call<ArrayList<Post>>, t: Throwable) {
                Toast.makeText(this@MainActivity, "Get post failed", Toast.LENGTH_LONG).show()
            }

            override fun onResponse(
                call: Call<ArrayList<Post>>,
                response: Response<ArrayList<Post>>) {
                response.body()?.let{
                    post ->
                    adapter?.updateData(post)
                }?: kotlin.run {
                    Toast.makeText(this@MainActivity, "Get post failed", Toast.LENGTH_LONG).show()
                }

            }

        })

    }

*and have the error *

Type mismatch: inferred type is <no name provided> but Callback<Post!>! was expected

in call.enqueue(object : Callback<ArrayList<Post>> Callback ArrayList dont wanna work with object, idk why

Pls help this it


Solution

  • It's possible that you've imported a package with the same name as the one you actually meant to import.

    Source: This just happened to me. Sometimes I don't read the package names closely enough when IntelliJ auto-imports new classes.