Checkout the article on Medium
retrofit2-kotlin-coroutines-call-adapter's Introduction
retrofit2-kotlin-coroutines-call-adapter's People
Forkers
dhruvan-complitech luboganev kotlinapps4 vsrinivasan81 ravik1swiggy mohsen2986 peachicetea minminaya leyvien frigidblade7 koladem rudykonio sambroad weiyih bestming8 tanlocle0495 ganeshsamant007 alanchienyl smahdifatemi pavel163 nejatboy phanii virendersran01 pprochot williamhqs boriskunda mironoff2007 junseokseo9306 ageback sezn flyknight2016 379107728retrofit2-kotlin-coroutines-call-adapter's Issues
Failed to invoke private NetworkResponse() with no args
I'm using RxJava and the ApiService is like:
@POST("url")
fun createThing(...): Single<NetworkResponse<MyResponseModel, ErrorModel>
And I use it like:
retrofitThing.createApi()
.subscribeOn(Schedulers.io)
.subscribe({
when(...
},
{
//ERROR: java.lang.RuntimeException: Failed to invoke private NetworkResponse() with no args
})
Then I get this error:
java.lang.RuntimeException: Failed to invoke private NetworkResponse() with no args
Unable to retrieve headers from call
Unable to create call adapter for NetworkResponse<DogResponse, DogError>
I am trying to do the same thing in my application and i get the above exception when i do the request.
I am using
// Retrofit Requests
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'
implementation 'com.squareup.retrofit2:converter-simplexml:2.8.1'
// Gson to Kotlin Object
implementation 'com.google.code.gson:gson:2.8.6'
The apiInterface has this call method
@POST(DogsApiUrl)
suspend fun suspendDogsRequest(@Body dogRequest: DogRequest): NetworkResponse<DogResponse, DogError>
And i provide Rertofit through Dagger2 and
@Provides
@Singleton
internal fun provideRetrofit(client: OkHttpClient): Retrofit.Builder {
return Retrofit.Builder()
.addCallAdapterFactory(NetworkResponseAdapterFactory())
.addConverterFactory(
GsonConverterFactory.create(GsonBuilder().setLenient().create()))
.client(client)
}
I call the request like that
val dogs = apiManager.dogsApiService().suspendDogsRequest(
DogRequest(Dog("pitbull", "Athens"))
)
when (dogs) {
is NetworkResponse.Success -> println("Success")
is NetworkResponse.ApiError -> println("ApiError")
is NetworkResponse.NetworkError -> println("NetWork Error")
is NetworkResponse.UnknownError -> println("Unknown error")
}
I can t understand why this does not work. What should i check?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.