Issue Fixed Update: Fixed by downgrading Firebase to 9.6.0 (just a random version I chose). I'm assuming the original issue has something to do with the emulator's good play or something.
Old Issue: So I need help, trying to set up Firebase Auth for logging in a user. I've enable this in my Firebase console and I've done this before and had it working as a class assignment weeks ago. But this time I'm getting a Null Object Reference when trying to login.
I'm starting to think this is related to my gradle files. mAuth isn't null, String email and password aren't null. I'm simply following this Firebase guide: https://firebase.google.com/docs/auth/android/password-auth
Full class below. Line 43 where the error begins (as from the screenshot) is 'mAuth.signInWithEmailAndPassword(email, password)'
package com.example.bri.inclass09;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
public class LoginActivity extends AppCompatActivity {
private FirebaseAuth mAuth;
private EditText emailET, passwordET;
private Button login, signup;
private static final String TAG = "test";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mAuth = FirebaseAuth.getInstance();
Log.d(TAG, "mAuth is: " + mAuth.toString());
login = findViewById(R.id.loginButton);
signup = findViewById(R.id.signupButton);
emailET = findViewById(R.id.loginEmailET);
passwordET = findViewById(R.id.loginPassET);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String email = emailET.getText().toString();
String password = passwordET.getText().toString();
Log.d(TAG, email + " " + password);
mAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(LoginActivity.this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "createUserWithEmail:success");
FirebaseUser user = mAuth.getCurrentUser();
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "createUserWithEmail:failure", task.getException());
Toast.makeText(LoginActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
// ...
}
});
}
});
}
@Override
public void onStart() {
super.onStart();
// Check if user is signed in (non-null) and update UI accordingly.
//FirebaseUser currentUser = mAuth.getCurrentUser();
}
}