I'm trying to retrieve a list of object "Game" from my firebase database using Kotlin on Android Studio.
I am using the code below:
private fun getGamesAvailable() {
var ref = FirebaseDatabase.getInstance().getReference("games")
var gamesMutableList: MutableList<Game> = mutableListOf()
val menuListener = object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
for (dataValues in dataSnapshot.children) {
val game: Game? = dataValues.getValue(Game::class.java)
gamesMutableList.add(game!!)
}
val adapter = GameAdapter(applicationContext, R.layout.games_list, gamesMutableList)
listViewGames.adapter = adapter
}
override fun onCancelled(databaseError: DatabaseError) {
// handle error
}
}
ref.addListenerForSingleValueEvent(menuListener)
}
but I get the error
com.google.firebase.database.DatabaseException: Expected a List while deserializing, but got a class java.util.HashMap
I understand that the problem is I am trying to retrieve a list of Games that has a list of Players, but I don't know how to solve this. I found some posts about it on stackoverflow but I don't really understand the answers and how they solve this problem.
Android-Expected a List while deserializing, but got a class java.util.HashMap
Expected a List while deserializing, but got a class java.util.HashMap
If anyone could help me understand I'll be very thankfull !