Complete Error:
"Attempt to invoke virtual method 'bolts.Task com.parse.ParseUser.signUpInBackground()' on a null object reference"
I am trying to make a login and sign up button, on clicking it the user must be signed in and if failed then signed up.
Here is my source code:
public void onClickLogInSignUp (View view)
{
EditText editTextUsername = (EditText) findViewById(R.id.editTextUsername);
EditText editTextPassword = (EditText) findViewById(R.id.editTextPassword);
username = editTextUsername.getText().toString();
password = editTextPassword.getText().toString();
ParseUser.logInInBackground(username, password, new LogInCallback()
{
@Override
public void done(ParseUser user, ParseException e)
{
Log.i("Parse","Trying to log in ");
if ( e == null )
{
Log.i("Parse","Log In Successful");
Log.i("Parse","Redirecting as "+ ParseUser.getCurrentUser().getUsername());
Toast.makeText(MainActivity.this, "Logged In", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(), UserList.class));
}
else
{
Log.e("Parse","Log In Failed Error - "+e.toString());
isLogInSuccessful = false;
ParseUser.getCurrentUser().signUpInBackground();
ParseUser.getCurrentUser().saveInBackground(new SaveCallback()
{
@Override
public void done(ParseException e)
{
ParseUser user = new ParseUser();
user.setUsername(username);
user.setPassword(password);
user.signUpInBackground(new SignUpCallback()
{
@Override
public void done(ParseException e)
{
if (e == null)
{
startActivity(new Intent(getApplicationContext(), UserList.class));
Log.i("Parse","Sign Up Successful");
Log.i("Parse","Redirecting as "+ ParseUser.getCurrentUser().getUsername());
Toast.makeText(MainActivity.this, "Signed Up", Toast.LENGTH_SHORT).show();
}
else
{
Log.e("Parse","Can't log in as well as signup.");
Toast.makeText(MainActivity.this, "Can't log in as well as signup.", Toast.LENGTH_SHORT).show();
}
}
});
}
});
}
}
});
}