Issue
I was trying to create a login system from my app, but it crashes when I open it. I managed to locate the bug to the line
mFirebaseAuth = FirebaseAuth.getInstance();
which makes no sense to me. Here is the code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Initialize Firebase Auth
mFirebaseAuth = FirebaseAuth.getInstance();
mFirebaseUser = mFirebaseAuth.getCurrentUser();
if (mFirebaseUser == null) {
// Not logged in, launch the Log In activity
loadLogInView();
}
}
private void loadLogInView() {
Intent intent = new Intent(this, LogInActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
}
and the crash report:
02-20 01:04:45.137 3186-3186/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.maegner.testingfirebase, PID: 3186
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.maegner.testingfirebase/com.maegner.testingfirebase.MainActivity}: java.lang.IllegalArgumentException: Given String is empty or null
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)..............
Solution
This exception can be caused by a misconfigured google-services.json
file. The error will occur if the api_key
is missing. Verify that your google-services.json
file contains this section:
"api_key": [
{
"current_key": "AIzaSyDkG-g8hH7T4TV7RrN23ccnRsXp12345678" //<-- your key here
}
],
If it does not, regenerate google-services.json
.
Answered By - Bob Snyder
Answer Checked By - Mildred Charles (JavaFixing Admin)