After some freezes, I get this error message.
I am not able to identify the reason for this problem. When I do Debug it shows that my app stops at different times. Sometimes it does 6 loops. Sometimes less or more. And the number of a DISPATCHER WORKER is not always the same in my ERROR message.
E/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-1
retrofit2.HttpException: HTTP 404 Not Found
at retrofit2.KotlinExtensions$await$2$2.onResponse(KotlinExtensions.kt:53)
at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:161)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:174)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Code:
class HeroesListViewModel (private val dbRepository: DbRepository) : ViewModel() {
val heroesData: LiveData<List<Hero>> = dbRepository.getAllHeroes()
var resultHeroes = ArrayList<Base>()
var heroes = ArrayList<Hero>()
init {
viewModelScope.launch(Dispatchers.IO) {
heroes = getAllHeroDetails()
dbRepository.addAllHeroes(heroes)
}
}
suspend fun getHeroTitles(): Heroes {
return dbRepository.getRemoteHeroes()
}
suspend fun getHero(uid:Int): Base {
return dbRepository.getRemoteHero(uid)
}
suspend fun getPlanet(uid:Int): PlanetBase {
return dbRepository.getRemotePlanet(uid)
}
suspend fun getFilms(): FilmsBase {
return dbRepository.getRemoteFilms()
}
suspend fun getAllHeroDetails(): ArrayList<Hero> {
val heroTitles = getHeroTitles()
val films = getFilms()
for (i in heroTitles.heroes.indices) {
resultHeroes.add(getHero(heroTitles.heroes[i].uid.toInt()))
heroes.add(resultHeroes[i].result.hero)
heroes[i].uid = resultHeroes[i].result.uid.toInt()
heroes[i].homeworld = getPlanet(
resultHeroes[i].result.hero.homeworld?.last()
.toString()
.toInt()
).result.planetProperties.name
heroes[i].films = ArrayList()
for (j in films.filmsResult.indices) {
if (heroes[i].url in films.filmsResult[j].filmsProperties.characters) {
heroes[i].films.add(films.filmsResult[j].filmsProperties.title)
}
}
}
return heroes
}
}
You need to evaluate your fields when debugging. It looks like one of your url is pointing to an invalid resource.