Advertisement
Guest User

Untitled

a guest
Sep 30th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.19 KB | None | 0 0
  1. public void signup() {
  2. Log.d(TAG, "Signup");
  3.  
  4. if (!validate()) {
  5. onSignupFailed();
  6. return;
  7. }
  8.  
  9.  
  10. final ProgressDialog progressDialog = new ProgressDialog(SignupActivity.this,
  11. R.style.AppTheme_Dark_Dialog);
  12. progressDialog.setIndeterminate(true);
  13. progressDialog.setMessage("Creating Account...");
  14. progressDialog.show();
  15.  
  16. mNewFirebaseUserEmail = _emailText.getText().toString();
  17. mNewFirebaseUserPassword = _passwordText.getText().toString();
  18.  
  19. new Handler().postDelayed(
  20. new Runnable() {
  21. public void run() {
  22. // On complete call either onSignupSuccess or onSignupFailed
  23. // depending on success
  24. onSignupSuccess();
  25. // onSignupFailed();
  26. progressDialog.dismiss();
  27. }
  28. }, 3000);
  29. onSignupSuccess();
  30. }
  31.  
  32. public void onSignupSuccess() {
  33. signupButton.setEnabled(true);
  34. //not sure why this line is here
  35. setResult(RESULT_OK, null);
  36. //this line below actually creates the user in Firebase; does not write or save to any locations
  37. mAuth.createUserWithEmailAndPassword(mNewFirebaseUserEmail, mNewFirebaseUserPassword)
  38. .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
  39. @Override
  40. public void onComplete(@NonNull Task<AuthResult> task) {
  41. Log.d(TAG, "signInWithEmail:onComplete:" + task.isSuccessful());
  42. FirebaseAuth loggedInAuth = FirebaseAuth.getInstance();
  43. NULL BEING THROWN HERE
  44. String ID = loggedInAuth.getCurrentUser().getUid();
  45. //TODO: Update handling of display name
  46. String displayName = mAuth.getCurrentUser().getUid();
  47. HashMap<String, Object> id = new HashMap<>();
  48. id.put("user_id", ID);
  49. id.put("display_name", displayName);
  50. mUserRef.child(ID).updateChildren(id);
  51.  
  52. // If sign in fails, display a message to the user. If sign in succeeds
  53. // the auth state listener will be notified and logic to handle the
  54. // signed in user can be handled in the listener.
  55. if (!task.isSuccessful()) {
  56. Log.w(TAG, "signInWithEmail:failed", task.getException());
  57. Toast.makeText(SignupActivity.this, "Authentication Failed with Email",
  58. Toast.LENGTH_SHORT).show();
  59. }
  60. }
  61. });
  62. }
  63.  
  64. 09-28 21:00:08.822 6591-6591/com.troychuinard.fanpolls E/AndroidRuntime: FATAL EXCEPTION: main
  65. Process: com.troychuinard.fanpolls, PID: 6591
  66. java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.firebase.auth.FirebaseUser.getUid()' on a null object reference
  67. at com.troychuinard.fanpolls.SignupActivity$5.onComplete(SignupActivity.java:279)
  68. at com.google.android.gms.tasks.zzc$1.run(Unknown Source)
  69. at android.os.Handler.handleCallback(Handler.java:739)
  70. at android.os.Handler.dispatchMessage(Handler.java:95)
  71. at android.os.Looper.loop(Looper.java:148)
  72. at android.app.ActivityThread.main(ActivityThread.java:5417)
  73. at java.lang.reflect.Method.invoke(Native Method)
  74. at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
  75. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  76.  
  77. mAuth.createUserWithEmailAndPassword(mNewFirebaseUserEmail, mNewFirebaseUserPassword)
  78. .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
  79. @Override
  80. public void onComplete(@NonNull Task<AuthResult> task) {
  81. if (task.isSuccessful()) {
  82. // Sign in success, update UI with the signed-in user's information
  83. Log.d(TAG, "createUserWithEmail:success");
  84. FirebaseUser user = mAuth.getCurrentUser();
  85. Log.d(TAG, "user:"+user.getUid());
  86. } else {
  87. // If sign in fails, display a message to the user.
  88. Log.w(TAG, "createUserWithEmail:failure", task.getException());
  89. Toast.makeText(EmailPasswordActivity.this, "Authentication failed.",
  90. Toast.LENGTH_SHORT).show();
  91. }
  92.  
  93. }
  94. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement