Quickstart-android: Error on getting Realtime Database reference in service

Created on 27 Jun 2016  路  8Comments  路  Source: firebase/quickstart-android

I am getting error:

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)聽`.

on

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

statement in service but its works fine in activity.

Most helpful comment

@ch-muhammad-adil is the service running in the same process as your Activity? If it's not, you would have an android:process="..." entry in the AndroidManfiest.xml for the service.

All 8 comments

@ch-muhammad-adil are you making any calls to the service in your Application's onCreate method? FirebaseApp is automatically initialized by a ContentProvider but this does not happen until after the Application#onCreate method has been called.

no I am starting service from activity using this method startService(intent) and service is sticky

@ch-muhammad-adil is the service running in the same process as your Activity? If it's not, you would have an android:process="..." entry in the AndroidManfiest.xml for the service.

@samtstern thanks this is the issue you are mentioning here now it's working fine after removing service separate process and running it on main application thread.

@ch-muhammad-adil glad this worked for you, thanks for following up.

good evening sir, I also experience this exception but in my case - I want my service(receiving child events) to run in separate process so that it still running whenever the main thread(App) is stopped or killed. how do I do this? hoping for your kind response. tnx :)

@pastillas could you post your question on StackOverflow and include some code to show your particular situation? That would be a better place to address this.

http://stackoverflow.com/questions/39642304/unable-to-get-databasereference-and-firebaseauth-currentuser-on-a-remoteseparat here is link sir thanks :)

Was this page helpful?
0 / 5 - 0 ratings