Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.RuntimeException: Failed to invoke private com.skydoves.sandwich.ApiResponse() with no args #29

Closed
JosephSanjaya opened this issue Aug 4, 2021 · 4 comments

Comments

@JosephSanjaya
Copy link

JosephSanjaya commented Aug 4, 2021

Please complete the following information:

  • Library Version 1.2.1
  • Affected Device(s) Pixel 4

Describe the Bug:
image
response that used Sandwich always failed, with exception like above

Expected Behavior:
Response should be success because implementation without Sandwich had no problem

Implementation:

@GET("api/v3/rekening/detail")
    suspend fun getRekeningDetail(
        @Header("Authorization") auth: String,
        @Query("id") id: String,
        @Query("type") type: String
    ): ApiResponse<ResponseResult<Rekening>>


data class ResponseResult<T>(
    @field:SerializedName("data")
    val data: T? = null,

    @field:SerializedName("message")
    val message: String? = null,

    @field:SerializedName("status")
    val status: Int? = null
)

fun getRekeningById(rekeningId: String, rekeningType: RekeningType) = flow {
        emit(State.Single.Loading())
        var rekeningData: Rekening? = null
        if (NetworkUtils.isConnected()) {
            val response =
                service.getRekeningDetail(
                    mSecuredPreferences.accessToken,
                    rekeningId,
                    rekeningType.value
                )
            response.suspendOnSuccess {
                dao.insertSyncData(listOf(data.data))
                rekeningData = dao.getRekeningById(rekeningId)
            }.suspendOnError {
                rekeningData = dao.getRekeningById(rekeningId)
            }.suspendOnException {
                rekeningData = dao.getRekeningById(rekeningId)
            }
        } else {
            rekeningData = dao.getRekeningById(rekeningId)
        }
        emit(State.Single.Success(rekeningData))
    }.flowOn(Dispatchers.IO)
@skydoves
Copy link
Owner

skydoves commented Aug 4, 2021

Hi, Could you share your Retrofit Builder?

@skydoves
Copy link
Owner

skydoves commented Aug 4, 2021

If you don't use the CoroutinesResponseCallAdapterFactory or use it with another factory, RuntimeException will happen.

@JosephSanjaya
Copy link
Author

this is my retrofit builder

val retrofit: Retrofit = Retrofit.Builder()
        .baseUrl(Secured.getBaseUrlApi(isBareksa))
        .client(okHttpClient)
        .addCallAdapterFactory(CoroutineCallAdapterFactory())
        .addConverterFactory(ScalarsConverterFactory.create())
        .addConverterFactory(GsonConverterFactory.create())
        .build()

ooh, I think this is the problem I thought it was the same as CoroutineCallAdapterFactory

@JosephSanjaya
Copy link
Author

Sorry, my bad it's fixed now

Thank you for fast response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants