无法为kotlinx.coroutines.flow.flow创建转换器,kotlinx.coroutines.flow.flow.flow no jsonadapter
在此演示应用程序中,我使用了翻新,Moshi,MVVM,Dagger Hilt和Kotlin Coroutine,我陷入了此例外,试图更改PokemonApiservice
删除它的悬挂式娱乐的结构,更改它,更改它,更改Flow< pokemonresponse>
to flow< proff< pokemonResponse>>
flow
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mml.pokemonkotlin, PID: 3282
java.lang.IllegalArgumentException: Unable to create converter for kotlinx.coroutines.flow.Flow<com.mml.pokemonkotlin.model.PokemonResponse>
for method PokemonApiService.getPokemons
at retrofit2.Utils.methodError(Utils.java:54)
at retrofit2.HttpServiceMethod.createResponseConverter(HttpServiceMethod.java:126)
at retrofit2.HttpServiceMethod.parseAnnotations(HttpServiceMethod.java:85)
at retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:39)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:202)
at retrofit2.Retrofit$1.invoke(Retrofit.java:160)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy1.getPokemons(Unknown Source)
at com.mml.pokemonkotlin.data.RemoteDataSource.getPokemons(RemoteDataSource.kt:24)
at com.mml.pokemonkotlin.viewmodels.PokemonViewModel$getPokemonList$1.invokeSuspend(PokemonViewModel.kt:26)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:367)
at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:30)
at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:25)
at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:110)
at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:126)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56)
at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47)
at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1)
at com.mml.pokemonkotlin.viewmodels.PokemonViewModel.getPokemonList(PokemonViewModel.kt:25)
at com.mml.pokemonkotlin.MainActivity.onCreate(MainActivity.kt:33)
at android.app.Activity.performCreate(Activity.java:7994)
at android.app.Activity.performCreate(Activity.java:7978)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.IllegalArgumentException: No JsonAdapter for kotlinx.coroutines.flow.Flow<com.mml.pokemonkotlin.model.PokemonResponse> (with no annotations)
at com.squareup.moshi.Moshi.adapter(Moshi.java:155)
at com.squareup.moshi.Moshi.adapter(Moshi.java:105)
at retrofit2.converter.moshi.MoshiConverterFactory.responseBodyConverter(MoshiConverterFactory.java:89)
at retrofit2.Retrofit.nextResponseBodyConverter(Retrofit.java:362)
at retrofit2.Retrofit.responseBodyConverter(Retrofit.java:345)
at retrofit2.HttpServiceMethod.createResponseConverter(HttpServiceMethod.java:124)
at retrofit2.HttpServiceMethod.parseAnnotations(HttpServiceMethod.java:85)
at retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:39)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:202)
at retrofit2.Retrofit$1.invoke(Retrofit.java:160)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy1.getPokemons(Unknown Source)
at com.mml.pokemonkotlin.data.RemoteDataSource.getPokemons(RemoteDataSource.kt:24)
at com.mml.pokemonkotlin.viewmodels.PokemonViewModel$getPokemonList$1.invokeSuspend(PokemonViewModel.kt:26)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:367)
at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:30)
at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:25)
at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:110)
at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:126)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56)
at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47)
at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1)
at com.mml.pokemonkotlin.viewmodels.PokemonViewModel.getPokemonList(PokemonViewModel.kt:25)
at com.mml.pokemonkotlin.MainActivity.onCreate(MainActivity.kt:33)
at android.app.Activity.performCreate(Activity.java:7994)
at android.app.Activity.performCreate(Activity.java:7978)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
@HiltAndroidApp
class BaseApplication : Application() {
}
模型类
Pokemon.kt
@JsonClass(generateAdapter = true)
data class Pokemon(
@Json(name = "name")
var name: String,
@Json(name = "url")
var url: String
)
口袋妖怪响应
@JsonClass(generateAdapter = true)
data class PokemonResponse(
@Json(name = "count")
var count: Int,
@Json(name = "next")
var next: String,
@Json(name = "previous")
var previous: String?,
@Json(name = "results")
var results: ArrayList<Pokemon>
)
PokemonApiservice接口
interface PokemonApiService {
@GET("pokemon")
suspend fun getPokemons() : Flow<PokemonResponse>
}
网络模块
@InstallIn(SingletonComponent::class)
@Module
object NetworkModule {
@Singleton
@Provides
fun provideHttpClient(): OkHttpClient {
return OkHttpClient.Builder().readTimeout(
15, TimeUnit.SECONDS
).connectTimeout(15, TimeUnit.SECONDS).build()
}
@Singleton
@Provides
fun provideMoshi(): Moshi {
return Moshi.Builder().build()
}
@Singleton
@Provides
fun provideRetrofitInstance(
okHttpClient: OkHttpClient,
): Retrofit {
return Retrofit.Builder()
.baseUrl("https://pokeapi.co/api/v2/")
.client(okHttpClient)
.addConverterFactory(MoshiConverterFactory.create(provideMoshi()))
.build()
}
@Singleton
@Provides
fun provideApiService(retrofit: Retrofit): PokemonApiService {
return retrofit.create(PokemonApiService::class.java)
}
}
remotedatasource类
class RemoteDataSource @Inject constructor(private val pokemonApiService: PokemonApiService) {
private val TAG = "RemoteDataSource"
suspend fun getPokemons(): PokemonResponse? {
var response: PokemonResponse? = null
pokemonApiService.getPokemons()
.catch { Log.e(TAG, "getPokemons: ${it.message}") }
.onEmpty { Log.e(TAG, "empty response ") }
.collect {
response = it
}
return response
}
}
PokemonViewModel
private const val TAG = "PokemonViewModel"
@HiltViewModel
class PokemonViewModel @Inject constructor(private val remoteDataSource: RemoteDataSource) :
ViewModel() {
var pokemonsResponse: MutableLiveData<ArrayList<Pokemon>> = MutableLiveData()
fun getPokemonList(){
viewModelScope.launch {
pokemonsResponse.value = remoteDataSource.getPokemons()?.results
}
}
}
口袋妖怪适配器
class PokemonAdapter : RecyclerView.Adapter<PokemonAdapter.PokemonViewHolder>() {
private var pokemonList = emptyList<Pokemon>()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PokemonViewHolder {
val binding = PokemonItemBinding.inflate(
LayoutInflater.from(parent.context),
parent, false
)
return PokemonViewHolder(binding)
}
override fun onBindViewHolder(holder: PokemonViewHolder, position: Int) {
val currentPokemon = pokemonList[position]
holder.bind(currentPokemon)
}
fun setList(pokemonList: ArrayList<Pokemon>){
this.pokemonList = pokemonList
notifyDataSetChanged()
}
override fun getItemCount(): Int {
return pokemonList.size
}
inner class PokemonViewHolder(private val binding: PokemonItemBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(pokemon: Pokemon) {
binding.pokemonNameTV.text = pokemon.name
}
}
}
,最后 MainActivity.kt
private const val TAG = "MainActivity"
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
private lateinit var pokemonViewModel: PokemonViewModel
private lateinit var binding: ActivityMainBinding
private lateinit var pokemonAdapter: PokemonAdapter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
pokemonViewModel = ViewModelProvider(this).get(PokemonViewModel::class.java)
pokemonAdapter = PokemonAdapter()
binding.pokemonRecyclerView.adapter = pokemonAdapter
pokemonViewModel.getPokemonList()
pokemonViewModel.pokemonsResponse.observe(this, {
if (it.isNullOrEmpty()) {
Log.e(TAG, "it is null")
} else {
pokemonAdapter.setList(it)
}
})
}
}
In this demo app, I used a retrofit, Moshi, MVVM, dagger hilt, and kotlin coroutine, I got stuck in this exception, I tried to change the structure of suspended fun in PokemonApiService
delete it, change the return type from Flow<PokemonResponse>
to Flow<Response<PokemonResponse>>
but all this didn't work
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mml.pokemonkotlin, PID: 3282
java.lang.IllegalArgumentException: Unable to create converter for kotlinx.coroutines.flow.Flow<com.mml.pokemonkotlin.model.PokemonResponse>
for method PokemonApiService.getPokemons
at retrofit2.Utils.methodError(Utils.java:54)
at retrofit2.HttpServiceMethod.createResponseConverter(HttpServiceMethod.java:126)
at retrofit2.HttpServiceMethod.parseAnnotations(HttpServiceMethod.java:85)
at retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:39)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:202)
at retrofit2.Retrofit$1.invoke(Retrofit.java:160)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy1.getPokemons(Unknown Source)
at com.mml.pokemonkotlin.data.RemoteDataSource.getPokemons(RemoteDataSource.kt:24)
at com.mml.pokemonkotlin.viewmodels.PokemonViewModel$getPokemonList$1.invokeSuspend(PokemonViewModel.kt:26)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:367)
at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:30)
at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:25)
at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:110)
at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:126)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56)
at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47)
at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1)
at com.mml.pokemonkotlin.viewmodels.PokemonViewModel.getPokemonList(PokemonViewModel.kt:25)
at com.mml.pokemonkotlin.MainActivity.onCreate(MainActivity.kt:33)
at android.app.Activity.performCreate(Activity.java:7994)
at android.app.Activity.performCreate(Activity.java:7978)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.IllegalArgumentException: No JsonAdapter for kotlinx.coroutines.flow.Flow<com.mml.pokemonkotlin.model.PokemonResponse> (with no annotations)
at com.squareup.moshi.Moshi.adapter(Moshi.java:155)
at com.squareup.moshi.Moshi.adapter(Moshi.java:105)
at retrofit2.converter.moshi.MoshiConverterFactory.responseBodyConverter(MoshiConverterFactory.java:89)
at retrofit2.Retrofit.nextResponseBodyConverter(Retrofit.java:362)
at retrofit2.Retrofit.responseBodyConverter(Retrofit.java:345)
at retrofit2.HttpServiceMethod.createResponseConverter(HttpServiceMethod.java:124)
at retrofit2.HttpServiceMethod.parseAnnotations(HttpServiceMethod.java:85)
at retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:39)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:202)
at retrofit2.Retrofit$1.invoke(Retrofit.java:160)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy1.getPokemons(Unknown Source)
at com.mml.pokemonkotlin.data.RemoteDataSource.getPokemons(RemoteDataSource.kt:24)
at com.mml.pokemonkotlin.viewmodels.PokemonViewModel$getPokemonList$1.invokeSuspend(PokemonViewModel.kt:26)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(DispatchedContinuation.kt:367)
at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:30)
at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(Cancellable.kt:25)
at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:110)
at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:126)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56)
at kotlinx.coroutines.BuildersKt.launch(Unknown Source:1)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47)
at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source:1)
at com.mml.pokemonkotlin.viewmodels.PokemonViewModel.getPokemonList(PokemonViewModel.kt:25)
at com.mml.pokemonkotlin.MainActivity.onCreate(MainActivity.kt:33)
at android.app.Activity.performCreate(Activity.java:7994)
at android.app.Activity.performCreate(Activity.java:7978)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
BaseAppliction class
@HiltAndroidApp
class BaseApplication : Application() {
}
model classes
Pokemon.kt
@JsonClass(generateAdapter = true)
data class Pokemon(
@Json(name = "name")
var name: String,
@Json(name = "url")
var url: String
)
Pokemon response
@JsonClass(generateAdapter = true)
data class PokemonResponse(
@Json(name = "count")
var count: Int,
@Json(name = "next")
var next: String,
@Json(name = "previous")
var previous: String?,
@Json(name = "results")
var results: ArrayList<Pokemon>
)
PokemonApiService interface
interface PokemonApiService {
@GET("pokemon")
suspend fun getPokemons() : Flow<PokemonResponse>
}
Network Module
@InstallIn(SingletonComponent::class)
@Module
object NetworkModule {
@Singleton
@Provides
fun provideHttpClient(): OkHttpClient {
return OkHttpClient.Builder().readTimeout(
15, TimeUnit.SECONDS
).connectTimeout(15, TimeUnit.SECONDS).build()
}
@Singleton
@Provides
fun provideMoshi(): Moshi {
return Moshi.Builder().build()
}
@Singleton
@Provides
fun provideRetrofitInstance(
okHttpClient: OkHttpClient,
): Retrofit {
return Retrofit.Builder()
.baseUrl("https://pokeapi.co/api/v2/")
.client(okHttpClient)
.addConverterFactory(MoshiConverterFactory.create(provideMoshi()))
.build()
}
@Singleton
@Provides
fun provideApiService(retrofit: Retrofit): PokemonApiService {
return retrofit.create(PokemonApiService::class.java)
}
}
RemoteDataSource class
class RemoteDataSource @Inject constructor(private val pokemonApiService: PokemonApiService) {
private val TAG = "RemoteDataSource"
suspend fun getPokemons(): PokemonResponse? {
var response: PokemonResponse? = null
pokemonApiService.getPokemons()
.catch { Log.e(TAG, "getPokemons: ${it.message}") }
.onEmpty { Log.e(TAG, "empty response ") }
.collect {
response = it
}
return response
}
}
PokemonViewModel
private const val TAG = "PokemonViewModel"
@HiltViewModel
class PokemonViewModel @Inject constructor(private val remoteDataSource: RemoteDataSource) :
ViewModel() {
var pokemonsResponse: MutableLiveData<ArrayList<Pokemon>> = MutableLiveData()
fun getPokemonList(){
viewModelScope.launch {
pokemonsResponse.value = remoteDataSource.getPokemons()?.results
}
}
}
pokemon adapter
class PokemonAdapter : RecyclerView.Adapter<PokemonAdapter.PokemonViewHolder>() {
private var pokemonList = emptyList<Pokemon>()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PokemonViewHolder {
val binding = PokemonItemBinding.inflate(
LayoutInflater.from(parent.context),
parent, false
)
return PokemonViewHolder(binding)
}
override fun onBindViewHolder(holder: PokemonViewHolder, position: Int) {
val currentPokemon = pokemonList[position]
holder.bind(currentPokemon)
}
fun setList(pokemonList: ArrayList<Pokemon>){
this.pokemonList = pokemonList
notifyDataSetChanged()
}
override fun getItemCount(): Int {
return pokemonList.size
}
inner class PokemonViewHolder(private val binding: PokemonItemBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(pokemon: Pokemon) {
binding.pokemonNameTV.text = pokemon.name
}
}
}
and finally MainActivity.kt
private const val TAG = "MainActivity"
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
private lateinit var pokemonViewModel: PokemonViewModel
private lateinit var binding: ActivityMainBinding
private lateinit var pokemonAdapter: PokemonAdapter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
pokemonViewModel = ViewModelProvider(this).get(PokemonViewModel::class.java)
pokemonAdapter = PokemonAdapter()
binding.pokemonRecyclerView.adapter = pokemonAdapter
pokemonViewModel.getPokemonList()
pokemonViewModel.pokemonsResponse.observe(this, {
if (it.isNullOrEmpty()) {
Log.e(TAG, "it is null")
} else {
pokemonAdapter.setList(it)
}
})
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
到目前为止,我不确定 reatrofit suports
flow
,我想事实并非如此。您可以从返回类型中删除它:As of now I'm not sure if Retrofit suports
Flow
, I guess it doesn't. You can remove it from the returning type:进行了一些搜索后,我发现这个答案第二个例外的解决方案,我将此行添加到依赖项中,
我也更改了我更改了返回
getPokemons的
类型还
after doing some search I found this answer the solution for the second exception, I add this line to the dependencies
I also changed the return type of
getPokemons
fun fromFlow
toPokemonResponse
,finally, I changed results from ArrayList to List because the Moshi doesn't support it yet