为什么实时数据库中的数据在Logcat Kotlin中没有错误而无法写入?

huangapple go评论99阅读模式
英文:

Why is data in Realtime database not writing with no error in logcat Kotlin

问题

  1. fun updateDatabase(num: String, titlexp: String, gorl: String) {
  2. val expID = dbref.push().key!!
  3. val expense = expenseModel(titlexp, num.toInt(), gorl)
  4. dbref.child("expenses").child(expID).setValue(expense)
  5. .addOnSuccessListener {
  6. Toast.makeText(applicationContext, "Expense Added", Toast.LENGTH_LONG).show()
  7. }.addOnFailureListener { err ->
  8. Toast.makeText(applicationContext, "Expense not added due to error ${err.message}", Toast.LENGTH_LONG).show()
  9. }
  10. }
  1. {
  2. "rules": {
  3. ".read": true,
  4. ".write": true
  5. }
  6. }

为什么实时数据库中的数据在Logcat Kotlin中没有错误而无法写入?
此外,我已经在AndroidManifest.xml中允许了互联网和访问网络状态权限。

英文:
  1. fun updateDatabse(num:String, titlexp:String, gorl:String)
  2. {
  3. val expID=dbref.push().key!!
  4. val expense=expenseModel(titlexp,num.toInt(),gorl)
  5. //DataNotAdding after executing the following line the debug cursor exits the function
  6. dbref.child("expenses").child(expID).setValue(expense)
  7. .addOnSuccessListener{
  8. Toast.makeText(applicationContext,"Expense Added",Toast.LENGTH_LONG).show()
  9. }.addOnFailureListener{err->
  10. Toast.makeText(applicationContext,"Expense not added due to error ${err.message}",Toast.LENGTH_LONG).show()
  11. }
  12. }
  13. }

为什么实时数据库中的数据在Logcat Kotlin中没有错误而无法写入?
Also, I have already allowed for Internet and access network state permission in Android Manifest.xml
My rules in the console are as follows:-

  1. {
  2. "rules": {
  3. ".read": true,
  4. ".write": true,
  5. }
  6. }

答案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.

huangapple
  • 本文由 发表于 2023年6月29日 05:07:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76576712.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定