Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void signup() {
- Log.d(TAG, "Signup");
- if (!validate()) {
- onSignupFailed();
- return;
- }
- final ProgressDialog progressDialog = new ProgressDialog(SignupActivity.this,
- R.style.AppTheme_Dark_Dialog);
- progressDialog.setIndeterminate(true);
- progressDialog.setMessage("Creating Account...");
- progressDialog.show();
- mNewFirebaseUserEmail = _emailText.getText().toString();
- mNewFirebaseUserPassword = _passwordText.getText().toString();
- new Handler().postDelayed(
- new Runnable() {
- public void run() {
- // On complete call either onSignupSuccess or onSignupFailed
- // depending on success
- onSignupSuccess();
- // onSignupFailed();
- progressDialog.dismiss();
- }
- }, 3000);
- onSignupSuccess();
- }
- public void onSignupSuccess() {
- signupButton.setEnabled(true);
- //not sure why this line is here
- setResult(RESULT_OK, null);
- //this line below actually creates the user in Firebase; does not write or save to any locations
- mAuth.createUserWithEmailAndPassword(mNewFirebaseUserEmail, mNewFirebaseUserPassword)
- .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
- @Override
- public void onComplete(@NonNull Task<AuthResult> task) {
- Log.d(TAG, "signInWithEmail:onComplete:" + task.isSuccessful());
- FirebaseAuth loggedInAuth = FirebaseAuth.getInstance();
- NULL BEING THROWN HERE
- String ID = loggedInAuth.getCurrentUser().getUid();
- //TODO: Update handling of display name
- String displayName = mAuth.getCurrentUser().getUid();
- HashMap<String, Object> id = new HashMap<>();
- id.put("user_id", ID);
- id.put("display_name", displayName);
- mUserRef.child(ID).updateChildren(id);
- // 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.
- if (!task.isSuccessful()) {
- Log.w(TAG, "signInWithEmail:failed", task.getException());
- Toast.makeText(SignupActivity.this, "Authentication Failed with Email",
- Toast.LENGTH_SHORT).show();
- }
- }
- });
- }
- 09-28 21:00:08.822 6591-6591/com.troychuinard.fanpolls E/AndroidRuntime: FATAL EXCEPTION: main
- Process: com.troychuinard.fanpolls, PID: 6591
- java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.firebase.auth.FirebaseUser.getUid()' on a null object reference
- at com.troychuinard.fanpolls.SignupActivity$5.onComplete(SignupActivity.java:279)
- at com.google.android.gms.tasks.zzc$1.run(Unknown Source)
- at android.os.Handler.handleCallback(Handler.java:739)
- at android.os.Handler.dispatchMessage(Handler.java:95)
- at android.os.Looper.loop(Looper.java:148)
- at android.app.ActivityThread.main(ActivityThread.java:5417)
- at java.lang.reflect.Method.invoke(Native Method)
- at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
- at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
- mAuth.createUserWithEmailAndPassword(mNewFirebaseUserEmail, mNewFirebaseUserPassword)
- .addOnCompleteListener(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();
- Log.d(TAG, "user:"+user.getUid());
- } else {
- // If sign in fails, display a message to the user.
- Log.w(TAG, "createUserWithEmail:failure", task.getException());
- Toast.makeText(EmailPasswordActivity.this, "Authentication failed.",
- Toast.LENGTH_SHORT).show();
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement