I'm building an app in Android Studio and using Firebase to store the data that the app will display. However, when I try to execute the following line of code, I get an error:
FirebaseFirestore db = FirebaseFirestore.getInstance();
The full error looks like this:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist.
at com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:165)
at com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:136)
at com.google.firebase.firestore.FirebaseFirestore.getInstance(com.google.firebase:firebase-firestore@@17.1.2:68)
at com.example.csc2022_app.DatabaseUtil.<init>(DatabaseUtil.java:15)
at com.example.csc2022_app.DatabaseUtil.main(DatabaseUtil.java:44)
Process finished with exit code 1
To be clear, DatabaseUtil.java:15 is the line above, and DatabaseUtil.java:44 simply makes a new object of DatabaseUtil.
As per this question my app's build.gradle file already contains the line
apply plugin: 'com.google.gms.google-services'
which made absolutely no difference.
If it helps, I have been following the instructions in Android Studio under Tools > Firebase > Firestore, and up to step 3 everything was dandy. It says it is connected, and it says that the dependencies are set up correctly.
Please help, this project is the bane of my existence at this point.
ETA: I have followed the instructions under "Option 1" on this page: https://firebase.google.com/docs/android/setup and have added the google-services.json file to the project.