Reputation: 73
I am trying to make a basic connection to firebase within a Java app, and using the basic code provided I am unable to get any response at all.
Here is the code I am using:
package fix;
import com.firebase.client.*;
public class Main {
public static void main(String args[]) throws Exception {
String url = "https://----.firebaseIO.com/";
Firebase dataRef = new Firebase(url);
dataRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
System.out.println("data");
}
@Override
public void onCancelled() {
System.err.println("Listener was cancelled");
}
});
System.out.println("hi");
}
}
The library seems to be loading fine. Any suggestions?
Update
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Raising events for /.info/authenticated
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Doing onDiff with changes: []
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Marking queries complete for /.info/authenticated
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Marking queries complete for /.info/authenticated
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Marking queryMap complete:null
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Marking queries complete for /.info/authenticated
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Marking queryMap complete:null
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Raising events for /.info/connected
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Doing onDiff with changes: []
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Marking queries complete for /.info/connected
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Marking queries complete for /.info/connected
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Marking queryMap complete:null
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Marking queries complete for /.info/connected
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Marking queryMap complete:null
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] ViewManager: Adding Value Event Listener callback for path: /
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] PersistentConnection: pc_0 - Listening on / for [{}]
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] PersistentConnection: pc_0 - Adding listen params: [{}]
[java] Fri Sep 06 09:54:43 PDT 2013 [DEBUG] EventRaiser: Raising 0 event(s)
[java] wait
[java] wait
[java] wait
[java] wait
Upvotes: 7
Views: 13947
Reputation: 1434
Firebase Engineer here, can you enable logging and post the output? You can enable logging by doing:
Firebase.getDefaultConfig().setLogLevel(Logger.Level.DEBUG);
Also, can you add an observer for
dataRef.child(".info/connected");
And log the events that you get from it? That will tell you when you are connected or disconnected from Firebase.
Edit: This was resolved over email. It was a bug in the client library, which is now resolved. You can download the latest version from the website: https://www.firebase.com/docs/downloads.html
Upvotes: 2
Reputation: 33389
I believe the probelm is that, unlike Node.js which keeps running waiting for events and callbacks to fire, Java quits when it reaches the end of the main method. You'll want to keep the main thread from quitting. Something like this should keep the main thread from terminating.
while(true) {
Thread.Sleep(10000); //Sleep 10 seconds
}
Upvotes: 4