I am trying to get data from a firebase database. The breakpoints show it is getting the data, but it looks like I am not properly assigning it to my class.
which causes this exception :
java.lang.ClassCastException: java.util.HashMap cannot be cast to Class
override fun onDataChange(p0: DataSnapshot?) {
if (p0!!.exists()){
val children = p0!!.children
children.forEach {
println(it.value.toString())
var item : DashboardItem = it.value as DashboardItem
println(item)
}
}
}
this is the DB export :
{
"dashboard" : [
{ "name" : "News"},
{ "name" : "Chatroom"},
{ "name" : "Music"},
{ "name" : "Quotes"},
{ "name" : "Reminder"},
{ "name" : "Poll"},
{ "name" : "Suggestion"},
{ "name" : "LogOut"} ]
}
the class object i want to create
data class DashboardItem(val name: String = "")