I am trying to retrieve the user's info after they log in from Firebase. I have the sneaking suspicion that this error isn't actually my problem - and has to deal with the fact that I'm using ServerValue.Timestamp
to store the date/time for a user when they've registered (as I'm trying to pull dateJoined back out, and my class has no idea what to do with it). My database looks something like this:
And when logging in, this is the code I use to grab the user's information
//grab user's name from firebase
//drill down to specific user
val usersRef = FirebaseDatabase.getInstance().getReference("Users")
val loggedInUserRef = usersRef.child(user.uid) //specific to the logged in user
val dataRef = loggedInUserRef.child("UserInfo") //get logged in user info
//attach listener
dataRef.addListenerForSingleValueEvent(object : ValueEventListener {
override fun onDataChange(dataSnapshot: DataSnapshot) {
// Get Post object and use the values to update the UI
val user_data = dataSnapshot.getValue(User::class.java)
Log.w(TAG, dataSnapshot.value.toString())
//add relevant data to shared preferences
prefs.userName = "$user_data.FirstName $user_data.LastName"
}
override fun onCancelled(databaseError: DatabaseError) {}
})
And I have my User class in a separate file here:
package androidproject.project_rc
data class User(
var FirstName: String = "",
var LastName: String = "",
var Email: String = "",
var Password: String = "",
var DateJoined: Any
)
Around this line: val user_data = dataSnapshot.getValue(User::class.java)
is where the error gets thrown - what gives?