Retrofit interface:

@GET("api")
fun fetchTests(): Call<ArrayList<Test>>

Activity code:

class HomeActivity : AppCompatActivity(), Callback<ArrayList<Test>> {
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_home)
    fetchTests()
}

private fun fetchTests() {
    val api = Api.getApiService()
    val call = api.fetchTests()
    call.enqueue(this)
}}

I can't pass the callback using this, it is passing the HomeActivity instance instead. However if i try to used Void or Any as the type of Call and Callback it works fine.

What could be the reason for this behavior?

Here is the Test class

data class Test(val name: String, val id: Int)

Additional Details:

I tried to do the inline callback method and this is the error message I got Image showing inline code error

Update: I don't know why I got downvoted for a genuine question this was clearly a problem with Android studio. Getting reputation points here is difficult downvoters should know that.

  • does this compile? Your activity is missing overrides for onResponse and onFailure – Tim Castelijns Sep 28 at 7:40
  • I have omitted those lines. just the lines where the problem is happening. Code doesn't compile and it give the error at the line where I am passing this to enqueue. I have checked it with simple types like Void and Any and it works fine. – NIKHIL MAURYA Sep 28 at 8:06

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.