英文:
Why is data in Realtime database not writing with no error in logcat Kotlin
问题
fun updateDatabase(num: String, titlexp: String, gorl: String) {
val expID = dbref.push().key!!
val expense = expenseModel(titlexp, num.toInt(), gorl)
dbref.child("expenses").child(expID).setValue(expense)
.addOnSuccessListener {
Toast.makeText(applicationContext, "Expense Added", Toast.LENGTH_LONG).show()
}.addOnFailureListener { err ->
Toast.makeText(applicationContext, "Expense not added due to error ${err.message}", Toast.LENGTH_LONG).show()
}
}
{
"rules": {
".read": true,
".write": true
}
}
此外,我已经在AndroidManifest.xml中允许了互联网和访问网络状态权限。
英文:
fun updateDatabse(num:String, titlexp:String, gorl:String)
{
val expID=dbref.push().key!!
val expense=expenseModel(titlexp,num.toInt(),gorl)
//DataNotAdding after executing the following line the debug cursor exits the function
dbref.child("expenses").child(expID).setValue(expense)
.addOnSuccessListener{
Toast.makeText(applicationContext,"Expense Added",Toast.LENGTH_LONG).show()
}.addOnFailureListener{err->
Toast.makeText(applicationContext,"Expense not added due to error ${err.message}",Toast.LENGTH_LONG).show()
}
}
}
Also, I have already allowed for Internet and access network state permission in Android Manifest.xml
My rules in the console are as follows:-
{
"rules": {
".read": true,
".write": true,
}
}
答案1
得分: 0
基本上,您需要在logcat中检查是否有与FirebaseDatabase相关的消息,如果出现未连接的消息,只需在项目文件中找到app->build->google-services.json下删除google-services.json文件。一旦删除了此文件,只需关闭Android Studio,然后使用工具->Firebase->然后RealTimeDatabase再次连接,这很可能会解决问题,就像对我来说一样。
英文:
Basically what you have to do is check in logcat for message or not connected with respect to FirebaseDatabase and if it comes to not connected just simply delete google-services.json found in project files under app ->build->google-services.json. Once you delete this file just simply close Android Studio and connect again using the FireBaseAssistant found in tools->Firebase-> then RealTimeDatabase. This will most probably fix the issue as it did for me as well.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论