This is running over a Servlet Module using Android Studio 2.3.2
private FirebaseApp app = null; // To avoid NullPointerExeception
private FirebaseDatabase database = FirebaseDatabase.getInstance(); // the error points here: FirebaseApp with name [DEFAULT] doesn't exist.
private DatabaseReference myRef = database.getReference("table/ID"); //Table from Firebase
This is inside the Get Method and I want to read just a value (Keep it simple). My problem is on setCredential it just say that "cannot resolve the method"
I got in the backend gradle file:
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.34'
compile 'com.google.appengine:appengine-api-1.0-sdk:1.9.53'
compile 'org.apache.httpcomponents:httpclient:4.5.3'
compile 'javax.servlet:servlet-api:2.5'
compile 'com.google.firebase:firebase-server-sdk:3.0.3'
compile 'com.google.firebase:firebase-admin:5.0.0'
I tried several different ways to implement the credentials, as you can see they are "//commented".
Just one is working Admin SDK 4+ "setServiceAccount" nowdays deprecated, if I compile and deploy it to App Engine and then Firebase want to read the table it says: java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist.
So I got two options here (I am open to hear everything from you):
- setCredentials doesn't work
setServiceAccount compiles but doesn't work
InputStream serviceAccount = this.getClass().getResourceAsStream("/WEB-INF/YourJsonFile.json"); //JsonFile from Account Services FirebaseOptions options = new FirebaseOptions.Builder() .setCredential(FirebaseCredentials.fromCertificate(serviceAccount)) // example (doesn't compile) //.setCredential(FirebaseCredentials.applicationDefault()) //same problem (doesn't compile) //.setServiceAccount(serviceAccount) //compiling & it throws the error: FirebaseApp with name [DEFAULT] doesn't exist. .setDatabaseUrl("https://YourDatabaseName.firebaseio.com") .build(); this.app = FirebaseApp.initializeApp(options);
And I am calling myRef to read the value like this:
myRef.addListenerForSingleValueEvent(new ValueEventListener() {
When I run the application, it point me to the line of FirebaseDatabase.getInstance (on the attributes)
Thanks