在单个Activity中使用2个或更多Firebase Realtime DB [英] Using 2 or more Firebase Realtime DB inside a single Activity

查看:110
本文介绍了在单个Activity中使用2个或更多Firebase Realtime DB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为Blaze计划的用户,我可以创建多个数据库实例,以使默认数据库不会停留在10万个同时连接上.事实是,我试图从两个数据库中调用数据,因为有些数据在数据库1内,而另一些数据在数据库2内.因此,在Kotlin中,我声明了Firebase Instances如下;

As a Blaze plan users I can create multiple database instances so that default database not gonna stuck at 100k simultaneous connections. Thing is, I'm trying to call the data from both database, because some data are inside Database 1, and some other are in Database 2. So, in Kotlin, I've declared my Firebase Instances as follow;

val db: DatabaseReference = FirebaseDatabase.getInstance().reference

上面的代码行适用于默认数据库(数据库1). 通常,如果我想从数据库2调用另一个活动的数据(现在还不行),我需要在getInstance()方法中包括实例名称,即HTTPS链接,如下所示;

Well the above line works for the default DB (Databse 1). Usually if I wanna call the data from Database 2 for another Activity (not this one right now), I need to include the instance name which is the HTTPS link in the getInstance() method as follow;

val dataBase: DatabaseReference = FirebaseDatabase.getInstance("https://projectName.firebasio.com").reference

在这种情况下,我尝试使用此2声明,这似乎给了我错误.

In this case, I've tried to use this 2 declaration and it seems to give me error.

附加图片:

Logcat仅声明它为E/AndroidRuntime:FATAL EXCEPTION:main,并且在第二次实例缩放为

Logcat only states that it is E/AndroidRuntime: FATAL EXCEPTION: main and occurs at the second instances decalration which is

 val dataBase: DatabaseReference = FirebaseDatabase.getInstance("https://projectName.firebasio.com").reference

Logcat:

原因:com.google.firebase.database.DatabaseException:无效 Firebase数据库路径:https//projectName.firebaseio.com.火力基地 数据库路径不得包含.",#","$","["或]" 在com.google.android.gms.internal.zzepf.zzqn(未知来源:52) 在com.google.android.gms.internal.zzepf.zzqo(未知来源:13) 在com.google.android.gms.internal.zzepd.zzqj(未知来源:131) 在com.google.firebase.database.FirebaseDatabase.getInstance(未知 资料来源:45) 在com.google.firebase.database.FirebaseDatabase.getInstance(未知 资料来源:14) 在paackageName.CountryList.(CountryList.kt:22) 在java.lang.Class.newInstance(本机方法) 在android.app.Instrumentation.newActivity(Instrumentation.java:1173) 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2708) 在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 在android.app.ActivityThread.-wrap11(未知来源:0) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1593) 在android.os.Handler.dispatchMessage(Handler.java:105) 在android.os.Looper.loop(Looper.java:164) 在android.app.ActivityThread.main(ActivityThread.java:6541) 在java.lang.reflect.Method.invoke(本机方法) 在com.android.internal.os.Zygote $ MethodAndArgsCaller.run(Zygote.java:240) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

Caused by: com.google.firebase.database.DatabaseException: Invalid Firebase Database path: https//projectName.firebaseio.com. Firebase Database paths must not contain '.', '#', '$', '[', or ']' at com.google.android.gms.internal.zzepf.zzqn(Unknown Source:52) at com.google.android.gms.internal.zzepf.zzqo(Unknown Source:13) at com.google.android.gms.internal.zzepd.zzqj(Unknown Source:131) at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source:45) at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source:14) at paackageName.CountryList.(CountryList.kt:22) at java.lang.Class.newInstance(Native Method) at android.app.Instrumentation.newActivity(Instrumentation.java:1173) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2708) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)  at android.app.ActivityThread.-wrap11(Unknown Source:0)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)  at android.os.Handler.dispatchMessage(Handler.java:105)  at android.os.Looper.loop(Looper.java:164)  at android.app.ActivityThread.main(ActivityThread.java:6541)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

推荐答案

第二次调用getInstance()的URL无效.它在"https"之后缺少冒号.

The URL in your second call to getInstance() is invalid. It's missing a colon after "https".

这篇关于在单个Activity中使用2个或更多Firebase Realtime DB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆