I am trying to do the MvP Pattern and I am separating firebase queries in the model part. I get null object reference exception when I call it on the presenter.
Model:
public class LoginModelz implements LoginContract.LoginModelz {
private LoginPresenter loginPresenter;
FirebaseAuth mAuth; //= FirebaseAuth.getInstance();
FirebaseUser currentuser;// = mAuth.getCurrentUser();
public LoginModelz(LoginPresenter loginPresenter) {
this.loginPresenter = loginPresenter;
}
public void FirebaseQuery(){
mAuth = FirebaseAuth.getInstance();
currentuser = mAuth.getCurrentUser();
}
}
Presenter:
public class LoginPresenter implements LoginContract.LoginPresenter {
private LoginView loginView;
private LoginModelz loginModelz;
public LoginPresenter(LoginView loginView) {
this.loginView = loginView;
}
public LoginPresenter(LoginModelz loginModelz) {
this.loginModelz = loginModelz;
}
@Override
public void OnLogin(String email, String password,final Context context) {
loginModelz.FirebaseQuery();
Log.e("asda",context.toString());
if(email.isEmpty() && password.isEmpty()){
loginView.OnLoginFail("Email and Password is empty");
return;
}
else if(email.isEmpty()){
loginView.OnLoginFail("Email is empty");
return;
}else if(password.isEmpty()){
loginView.OnLoginFail("Password is empty");
return;
}else {
loginView.ProgressShow("ASDASDASDASDSAd");
Log.e("emailpass", email+password);
**loginModelz.mAuth.signInWithEmailAndPassword(email,password)**
.addOnCompleteListener( new OnCompleteListener<AuthResult>()
I was getting an error from the loginmodelz.mAuth
. If i put the initializations in the method in the presenter class it works just fine, but when i separated it is getting a null object reference.
Interfaces
public interface LoginContract {
interface LoginView{
void OnLoginSuccess();
void OnLoginFail(String message);
void Onregister();
void ProgressShow(String messsagge);
void ProgressDismiss(String message);
void Alert();
}
interface LoginPresenter{
void OnLogin(String email,String password,final Context context);
void OnVerify(Context context);
}
interface LoginModelz{
void FirebaseQuery();
}
}
You have not initialized loginModelz. Change your presenter constructor implement