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

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

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
  }
}

为什么实时数据库中的数据在Logcat Kotlin中没有错误而无法写入?
此外,我已经在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()
            }

    }
}

为什么实时数据库中的数据在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:-

{
  "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.

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:

确定