gpt4 book ai didi

android - 在服务中获取实时数据库引用时出错

转载 作者:行者123 更新时间:2023-12-05 00:21:53 27 4
gpt4 key购买 nike

我收到错误:

06-24 10:41:36.497 17316-17316/com.example.waseem.geolocation:location_service E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.waseem.geolocation:location_service, PID: 17316 java.lang.RuntimeException: Unable to instantiate service com.example.waseem.geolocation.LocationService: java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist. at android.app.ActivityThread.handleCreateService(ActivityThread.java:3085) at android.app.ActivityThread.access$1900(ActivityThread.java:172) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1505) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5832) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) Caused by: java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist. at com.google.firebase.FirebaseApp.getInstance(Unknown Source) at com.google.firebase.FirebaseApp.getInstance(Unknown Source) at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source) at com.example.waseem.geolocation.LocationService.(LocationService.java:34) at java.lang.reflect.Constructor.newInstance(Native Method) at java.lang.Class.newInstance(Class.java:1650) at android.app.ActivityThread.handleCreateService(ActivityThread.java:3082) at android.app.ActivityThread.access$1900(ActivityThread.java:172)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1505)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:145)  at android.app.ActivityThread.main(ActivityThread.java:5832)  at java.lang.reflect.Method.invoke(Native Method)  at java.lang.reflect.Method.invoke(Method.java:372)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194) `.




DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference(); 

服务中的声明,但它在 Activity 中工作正常。

最佳答案

我自己找到了我的问题解决方案,问题是我收到了这个错误,因为我在不同的进程中运行我的服务,这些进程在我声明我的服务的 list 中定义:

android:process = "......"

当我删除它并且现在我的服务正在应用程序主进程上运行并且我没有收到任何错误并且它工作正常。

关于android - 在服务中获取实时数据库引用时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37991929/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com