Android: Retrieve data of a specific user from a Firebase database in kotlin

Viewed 19

i want to retrive my data from firebase after login but when successfully login the app automatic close

val user = FirebaseAuth.getInstance().currentUser val userid = user!!.uid

    database = FirebaseDatabase.getInstance()
    reference = database.getReference("Profile")

    val fullnameTextView = findViewById<View>(R.id.fname) as TextView
    val lastnameTextView = findViewById<View>(R.id.lname) as TextView
    val emailTextView = findViewById<View>(R.id.ProfileEmail) as TextView
    val numberTextView = findViewById<View>(R.id.number) as TextView
    val addressTextView = findViewById<View>(R.id.address) as TextView
    reference.child(userid).addListenerForSingleValueEvent(object : ValueEventListener {
        override fun onDataChange(dataSnapshot: DataSnapshot) {

            val name = dataSnapshot.child("Fullname").value as String?
            val email = dataSnapshot.child("Email").value as String?
            val lname = dataSnapshot.child("Lastname").value as String?
            val cnumber = dataSnapshot.child("Contacts").value as String?
            val address = dataSnapshot.child("Address").value as String?

            fullnameTextView.text = name
            lastnameTextView.text = email
            emailTextView.text = lname
            numberTextView.text = cnumber
            addressTextView.text = address
1 Answers

You need to give more information for another person to help you with the problem; either share your error report, piece of database you're reading from. You can still go through the official documentantion and see what you're doing wrong...

Firebase Documentantion

Related