Ali*_*med 2 data-binding api android kotlin retrofit2
我正在使用带有Patternkotlin的 android 系统。
发送和获取 api 调用。databindingMVVMRetrofit2
当我发送登录呼叫时,我总是崩溃,这是消息:
java.lang.IllegalArgumentException: Unable to create call adapter for class java.lang.Object
Run Code Online (Sandbox Code Playgroud)
我多次重新设计了响应,它实际上与我的 api 的响应相匹配。有什么帮助吗?
//my retrofit interface
interface RetrofitInterface {
@FormUrlEncoded
@POST("userLogin")
suspend fun userLogin(
@Field("userName") userName: String,
@Field("userPassword") userPassword: String
): Response<UserLoginResponse>
companion object {
operator fun invoke(
networkConnectionInterceptor: NetworkConnectionInterceptor
): RetrofitInterface {
val okHttpClient = OkHttpClient.Builder()
.addInterceptor(networkConnectionInterceptor)
.build()
return Retrofit.Builder()
.client(okHttpClient)
.baseUrl("http://muUrlIsCorrect/")
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(RetrofitInterface::class.java)
}
}
}
//My response class
data class UserLoginResponse(
var error: Boolean?,
var message: String?,
var user: User?
)
Run Code Online (Sandbox Code Playgroud)
我认为您忘记添加.addCallAdapterFactoryRetrofit.Builder().addCallAdapterFactory(CoroutineCallAdapterFactory())如果您使用的是 coroutines-kotlin,请添加,否则您可以添加.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
Retrofit.Builder()
.baseUrl(BuildConfig.BASE_URL)
.addCallAdapterFactory(CoroutineCallAdapterFactory())
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(ApiInterface::class.java)
Run Code Online (Sandbox Code Playgroud)
试试这个
| 归档时间: |
|
| 查看次数: |
3384 次 |
| 最近记录: |