Recently I've been forced to reset the android device I've been working with and since then my app crashes each time I try to sign-up or log-in.
In other devices or in the emulator everything work as s it should so the problem isn't in the code (but if it's necessary I'll add it). The Android device is: Lenovo S90-u.
The error:
E/UncaughtException: java.lang.NullPointerException
at com.google.android.gms.internal.zzdtp.zzb(Unknown Source)
at com.google.android.gms.internal.zzdtw.zzb(Unknown Source)
at com.google.firebase.auth.FirebaseAuth.signInWithEmailAndPassword(Unknown Source)
at easytobook.com.easytobook.Account.LoginFragment$2.onClick(LoginFragment.java:90)
at android.view.View.performClick(View.java:4460)
at android.view.View$PerformClick.run(View.java:18649)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5345)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:855)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:671)
at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime: FATAL EXCEPTION: main
Process: easytobook.com.easytobook, PID: 7734
java.lang.NullPointerException
at com.google.android.gms.internal.zzdtp.zzb(Unknown Source)
at com.google.android.gms.internal.zzdtw.zzb(Unknown Source)
at com.google.firebase.auth.FirebaseAuth.signInWithEmailAndPassword(Unknown Source)
at easytobook.com.easytobook.Account.LoginFragment$2.onClick(LoginFragment.java:90)
at android.view.View.performClick(View.java:4460)
at android.view.View$PerformClick.run(View.java:18649)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5345)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:855)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:671)
at dalvik.system.NativeStart.main(Native Method)
the code:
public class LoginFragment extends Fragment{
private EditText inputEmail, inputPassword;
private ProgressBar progressBar;
private Button btnLogin, btnReset;
private FirebaseAuth auth;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate( R.layout.fragment_login, container, false );
auth = FirebaseAuth.getInstance(); //Get Firebase auth instance
if (auth.getCurrentUser() != null)
{
startActivity(new Intent(getActivity(), MainActivity.class));
getActivity().finish();
}
//setContentView(R.layout.fragment_login);
inputEmail = (EditText) view.findViewById(R.id.email);
inputPassword = (EditText) view.findViewById(R.id.password);
progressBar = (ProgressBar) view.findViewById(R.id.progressBar);
btnLogin = (Button) view.findViewById(R.id.btn_login);
btnReset = (Button) view.findViewById(R.id.btn_reset_password);
auth = FirebaseAuth.getInstance(); //Get Firebase auth instance
btnReset.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
startActivity(new Intent(getActivity(), ResetPasswordActivity.class));
getActivity().finish();
}
});
btnLogin.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
String email = inputEmail.getText().toString();
final String password = inputPassword.getText().toString();
if (TextUtils.isEmpty(email)) //email check
{
Toast.makeText(getActivity().getApplicationContext(), "enter mail", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(password)) //password check
{
Toast.makeText(getActivity().getApplicationContext(), "enter password", Toast.LENGTH_SHORT).show();
return;
}
progressBar.setVisibility(View.VISIBLE);
//authenticate user
auth.signInWithEmailAndPassword(email, password).addOnCompleteListener(getActivity(), new OnCompleteListener<AuthResult>()
{
@Override
public void onComplete(@NonNull Task<AuthResult> task)
{
// If sign in fails, display a message to the user. If sign in succeeds
// the auth state listener will be notified and logic to handle the
// signed in user can be handled in the listener.
progressBar.setVisibility(View.GONE);
try
{
if (!task.isSuccessful()) // there was an error
{
Toast.makeText(getActivity().getApplicationContext(), getString(R.string.auth_failed), Toast.LENGTH_LONG).show();
}
else {
//move to the next screen
Intent intent = new Intent(getActivity(), ProfileActivity.class);
startActivity(intent);
getActivity().finish();
}
}
catch(Exception e)
{
Toast.makeText(getActivity().getApplicationContext(),e.getMessage(), Toast.LENGTH_LONG).show();
}
}
});
}
});
return view;
}
}