In Firebase Realtime Database, already have user node. I need to create another node named BankDetails but when I try to enter details It gets an error. not created Another node.
Here's My code. It's on the fragment.
val database = Firebase.database
val myRef = database.getReference("BankDetails")
view.rechargeAmount.setOnClickListener {
if( emailBankText.text.trim().isNotEmpty()) {
val bankAccNo = bankAccText.getText().toString()
val accountBalance = amountText.getText().toString().toDouble()
val encodedEmail = encodeUserEmail(emailBankText.toString())
val bankDetails1 = BankDetails(encodedEmail,bankAccNo,accountBalance)
myRef.child(encodedEmail).setValue(bankDetails1).addOnSuccessListener {
Toast.makeText(activity, "updated successfully", Toast.LENGTH_LONG).show()
} .addOnFailureListener{
Toast.makeText(activity, "not updated", Toast.LENGTH_LONG).show()
}
}
else{
Toast.makeText(activity, "error", Toast.LENGTH_LONG).show()
}
This's the error I got com.google.firebase.database.DatabaseException: Invalid Firebase Database path
Is there anything wrong in my code. Help me, I'm new to Kotlin.
edit
I created another node and add some test data. but
CodePudding user response:
BankDetails
does not exist, so myRef
variable cannot be initialized because they can't find this node, you need to create this node by adding some test data inside the node and then the problem should be fixed.
CodePudding user response:
The problem in your code is due to the use of a .
inside a value that will be added as a key in the Realtime Database, which is actually not possible. You should always encode the email address to:
[email protected] -> name@email,com
As explained in my answer from the following post: