Error on getting Realtime Database reference in service.

297 views
Skip to first unread message

faris....@phaedrasolutions.com

unread,
Jun 24, 2016, 10:42:12 AM6/24/16
to Firebase Google Group
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.<init>(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.

Aron Deak

unread,
Jun 28, 2016, 10:13:48 AM6/28/16
to Firebase Google Group
You are using FirebaseDatabase in a separate process (location_service), where FirebaseApp has not yet been initialized.
In the main process, where the activity runs, it is initialized by FirebaseInitProvider.

To initialize the default FirebaseApp instance in location_service, you can use this code:
FirebaseApp.initializeApp(this /*context */, FirebaseOptions.fromResource(this /* context */);
Reply all
Reply to author
Forward
0 new messages