0

I get 2 data class responses, one at a time, from the network call. I used a sealed class for that but got a response error on the sealed class mentioning, "Failed to invoke private [packagename].LiveExamResponse() with no args"

on logcat I'm getting the correct response from the API call, just not being able to map it to the sealed class.

sealed class LiveExamResponse {
    data class LiveExamQuestion(val response: LiveExamQuestionResponse) : LiveExamResponse()
    data class Other(val response: OtherResponse) : LiveExamResponse()
    constructor() // public constructor without arguments

}
Sijan Neupane
  • 116
  • 2
  • 8
  • A sealed class is abstract. It cannot be instantiated. Its constructor is only for its subclasses to call inside their constructors. Apparently you are trying to use this abstract class as the return type from a Retrofit function, which doesn't make sense. But I have very little Retrofit experience so I can't help further. You probably need to add to your question your code where you define the function that is trying to construct a LiveExamResponse. – Tenfour04 Mar 30 '23 at 15:01
  • @Tenfour04 I tried with wrapper class too. for single datclass, its working fine. but with sealed class, I'm just not being able to figure out what's wrong. Indeed I'm trying to use the sealed class as a return type of function in the API Interface class. But isn't that how it is done? – Sijan Neupane Mar 30 '23 at 15:21

0 Answers0