问题
Due to this line in my codes :
var myRef = child_myRef.child(FirebaseAuth.getInstance().uid)
回答1:
The reason because your FirebaseAuth.getInstance().uid
is String?
(can be Null), but input of .child()
need a String
(none Null), so please check null before that:
FirebaseAuth.getInstance().uid?.let{
var myRef = child_myRef.child(it)
.....
}
Or if you make sure FirebaseAuth.getInstance().uid
never Null, you can using FirebaseAuth.getInstance().uid!!
, but It not is a good approach
回答2:
You can replace it with child_myRef.child(FirebaseAuth.getInstance().uid!!)
or check for null
.
回答3:
var myRef = child_myRef.child(FirebaseAuth.getInstance().getCurrentUser().getUid())
myRef.child("jina").setValue(Fname.text.toString())
myRef.child("tarehe").setValue(bDate.text.toString())
myRef.child("place").setValue(place.text.toString())
Hope you are trying to put all the details under user id.
So if thats the case kindly change your reference to myRef.
So you can put it under your user id all the above details.
回答4:
Its because the value of FirebaseAuth.getInstance().uid
can be null
, so first check if its not null , then perform your operation .
if(FirebaseAuth.getInstance().uid!=null){
var myRef = child_myRef.child(FirebaseAuth.getInstance().uid)
myRef.child("jina").setValue(Fname.text.toString())
myRef.child("tarehe").setValue(bDate.text.toString())
myRef.child("place").setValue(place.text.toString())
}
If you check with
FirebaseAuth.getInstance().uid!!
this will cause aNull Pointer Exception
and your app will crash ifFirebaseAuth.getInstance().uid
value comes asnull
, so try the above approach (as i wrote sample)
回答5:
This line works : child_myRef.child(FirebaseAuth.getInstance().uid!!) and now it is good.
My codes now are like the second image. Thak you all for your help.
来源:https://stackoverflow.com/questions/52921767/type-mismatch-inferred-type-is-string-but-string-was-expected