Reputation: 45
When i try get user information by his uid which is same like in firebase database this error is shown.
uid is passed in right way I have checked it. Route to database is good and I have checked this too.
Here is my code and this probably don't have any mistakes because everything work and only Firebase had some problems.
class Profil : AppCompatActivity() {
private var fAuth: FirebaseAuth?=null
private var database: DatabaseReference?=null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_profil)
fAuth= FirebaseAuth.getInstance()
// ✋ Here I checked with uid and uid.toString()
var userCheck = fAuth!!.currentUser?.uid.toString()
getData(userCheck)
// ✋ Here I checked that good uid is get
//tv_firsName.text = userCheck
}
private fun getData(userCheck: String) {
database = FirebaseDatabase.getInstance().getReference("Users")
database!!.child(userCheck).get().addOnSuccessListener{
if(it.exists()){
val firstName = it.child("firstName").value
val lastName = it.child("lastName").value
val position = it.child("position").value
val email = it.child("email").value
tv_Imie.text = firstName.toString()
tv_Nazwisko.text = lastName.toString()
tv_Stanowisko.text = position.toString()
tv_Email.text = email.toString()
}else{
Toast.makeText(this, "User does not exist", Toast.LENGTH_SHORT).show()
}
}.addOnFailureListener{
Toast.makeText(this, "Failed", Toast.LENGTH_SHORT).show()
Log.e("firebase", "Error getting data", it)
}
}
}
Here is my database structure
I checked some ways to solve this problem.
I have seen some people propose a solution with addValueEventListener
, but then the list is fetched. I want single user information to be included in my textViews. I read that the problem may be related to a bug in Firebase and not in the code.
Upvotes: 0
Views: 483
Reputation: 45
Ok, problem was with Firebase not my application. I don't know why but when I started app in every try Firebase closed my connection with database. I tried add to google.services.json some links to database and change some settings but this didn't work. After all I removed app from firebase and delete file google.services.json. I added app again on website then I connect app with firebase and new google.services.json was set. That's all everything is working thanks for help.
Upvotes: 1