I have recently began migrating from the old Firebase API into the new Google Firebase. I have followed the Getting Started Guide and was able to create an admin access account and generate a JSON file, as well as successfully (I think) initialized the SDK using the example code:
FirebaseOptions options = new FirebaseOptions.Builder()
.setServiceAccount(new FileInputStream("C:\\FileStructure\\Test Dev Project-59ee6eb5842a.json"))
.setDatabaseUrl("https://test-dev-project-96fd5.firebaseio.com/")
.build();
FirebaseApp.initializeApp(options);
My problem is in pushing any information onto my database. I run the application (In NetBeans) and it runs with no issues.
// Create a database based on the initialized Firebase App
FirebaseDatabase database = FirebaseDatabase.getInstance();
// Reference to the root of the database created.
DatabaseReference ref = database.getReference();
// Create a child to the root node
DatabaseReference dataRef = ref.child("Hello World");
dataRef.setValue("I'm writing data", new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
if (databaseError != null) {
System.out.println("Data could not be saved " + databaseError.getMessage());
} else {
System.out.println("Data saved successfully.");
}
}
});
It is my understanding that the code draws a database reference based on the instantiated App, and setValue(), push(), update(), and transaction data pushes data back onto the database.
I have practically copied and pasted data directly from the new API reference page on saving data and the data still does not appear on my console. I can also add that my console does not even confirm that I have correctly or incorrectly pushed the data.
I feel as though I am forgetting something small, and I am not sure if I am creating my references correctly.
I am fairly new to actually posting on Stack Overflow, so please advise if I have left out important data or posted something correctly.
Thanks for your time, guys.