Pandaboy95
Pandaboy95

Reputation: 21

FirebaseError Exception Email/Password Authentication

I am using Firebase User Authentication, Email/Password method. I want to test whether i can change my email and i keep getting email invalid when it is correct and when i keep pressing change which is the button to start the change email method i get this.

FirebaseError: There was an exception while performing the request: Unexpected character ('<' (code 60)):expected a valid value(number,String,array,object,'true','false' or 'null')

at [Source:org.apache.http.conn.EofSensorInputStream@3f1bc11e; line:1,column:2]

Can anyone know how to solve this problem ?

public class ChangeEmail extends BaseActivity implements View.OnClickListener {

EditText Password, CurrentEmail, NewEmail;
String FirebaseUserNewEmail, FirebasePassword, FirebaseUserCurrentEmail;
Button buttonDone;
public static final String DEFAULT = "N/A";
String username;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /**
     * Adding our layout to parent class relative layout.
     */
    getLayoutInflater().inflate(R.layout.changeemail, RelativeLayout);

    CurrentEmail = (EditText) findViewById(R.id.CurrentEmail);
    NewEmail = (EditText) findViewById(R.id.NewEmail);
    buttonDone = (Button) findViewById(R.id.buttonDone);
    buttonDone.setOnClickListener(this);
    // Password - Edit Text
    Password = (EditText) findViewById(R.id.Password);
    // Make text style stay the same / as default
    Password.setTypeface(Typeface.DEFAULT);
    // Make password confidential.
    Password.setTransformationMethod(new PasswordTransformationMethod());

    SharedPreferences prefs = getSharedPreferences("project", 0);
    username = prefs.getString("keyusername", DEFAULT);

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(ChangeEmail.this);
    username = settings.getString("keyusername", DEFAULT);

    setTitle("Settings");

}

@Override
public void onResume() {
    super.onResume();
}

@Override
public void onPause() {
    super.onPause();
}

@Override
public void onStop() {
    super.onStop();
}

public void onDestroy() {
    super.onDestroy();
}

public void ChangeEmail()
{
    FirebaseUserCurrentEmail = CurrentEmail.getText().toString();
    FirebaseUserNewEmail = NewEmail.getText().toString();
    FirebasePassword = Password.getText().toString();
    System.out.println("Current Email :" + FirebaseUserCurrentEmail);
    System.out.println("New Email :" + FirebaseUserNewEmail);
    System.out.println("Password :" + FirebasePassword);
    Firebase ref = new Firebase("https://tapamp.firebaseio.com");
    ref.changeEmail(FirebaseUserCurrentEmail, FirebaseUserNewEmail, FirebasePassword, new Firebase.ResultHandler() {
        @Override
        public void onSuccess() {
            Toast.makeText(getApplicationContext(), "Welcome " + FirebaseUserNewEmail, Toast.LENGTH_SHORT).show();
            Intent a = new Intent(ChangeEmail.this, HomePage.class);
            startActivity(a);
        }
        @Override
        public void onError(FirebaseError firebaseError) {
            Toast.makeText(getApplicationContext(), "" + firebaseError, Toast.LENGTH_LONG).show();
            switch (firebaseError.getCode()) {
                case FirebaseError.USER_DOES_NOT_EXIST:
                    // handle a non existing user
                    break;
                case FirebaseError.INVALID_PASSWORD:
                    // handle an invalid password
                    break;
                case FirebaseError.INVALID_EMAIL:
                    Toast.makeText(getApplicationContext(), "Invalid Email" , Toast.LENGTH_SHORT).show();
                    break;
                default:
                    // handle other errors
                    break;
            }
        }
    });
}

@Override
public void onClick(View view) {
    if (view == buttonDone) {
        ChangeEmail();
    }
    else if (view == buttonLogout)
    {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                context);

        alertDialogBuilder.setIcon(R.drawable.trunk);
        alertDialogBuilder.setTitle("Log out"); // your dialog title
        // set dialog message
        alertDialogBuilder
                .setMessage("Are you sure?")
                .setCancelable(true)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        Intent a = new Intent(ChangeEmail.this, LoginPage.class);
                        a.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                        a.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        a.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                        finish();
                        startActivity(a);
                        Firebase ref = new Firebase("https://tapamp.firebaseio.com");
                        ref.unauth();
                    }
                })
                .setNegativeButton("No", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // if this button is clicked, just close
                        // the dialog box and do nothing
                        dialog.cancel();
                    }
                });

        // create alert dialog
        AlertDialog alertDialog = alertDialogBuilder.create();

        // show it
        alertDialog.show();
    }
}

}

Upvotes: 0

Views: 140

Answers (1)

Pandaboy95
Pandaboy95

Reputation: 21

The parameters given on the website is different from the parameters that is in the code. On the site, the parameters taken in is OldEmail, NewEmail, Password but in the code it is OldEmail, Password, NewEmail.

Upvotes: 2

Related Questions