When the application starts, it crashes - java

The problem is that when I run this code with authorization in Google, it immediately crashes:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAuth = FirebaseAuth.getInstance();
super.onStart();
// Check if user is signed in (non-null) and update UI accordingly.
FirebaseUser currentUser = mAuth.getCurrentUser();
updateUI(currentUser);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
//mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
mAuthListener = new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
} else {
}
}
};
et_email = (EditText) findViewById(R.id.et_email);
et_password = (EditText) findViewById(R.id.et_password);
mDetailTextView = (TextView) findViewById(R.id.mDetailTextView);
mStatusTextView = (TextView) findViewById(R.id.mStatusTextView);
findViewById(R.id.BVoiti).setOnClickListener(this);
findViewById(R.id.change_email).setOnClickListener(this);
findViewById(R.id.change_password).setOnClickListener(this);
findViewById(R.id.btn_vk).setOnClickListener(this);
findViewById(R.id.BReg).setOnClickListener(this);
}
#Override
public void onClick(View v) {
int i = v.getId();
if (i == R.id.btn_google) {
signIn();
}
}
private void signIn() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleSignInClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = task.getResult(ApiException.class);
firebaseAuthWithGoogle(account);
} catch (ApiException e) {
// Google Sign In failed, update UI appropriately
Log.w(TAG, "Google sign in failed", e);
// ...
}
}
}
public void signing(String email, String password){
mAuth.signInWithEmailAndPassword(email,password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(task.isSuccessful()) {
Toast.makeText(MainActivity.this, "Авторизация успешна", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(MainActivity.this, "Авторизация провалена", Toast.LENGTH_SHORT).show();
}
}
});
}
public void registration (String email, String password){
mAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
Toast.makeText(MainActivity.this, "Регистрация успешна, теперь войдите", Toast.LENGTH_SHORT).show();
} else{
Toast.makeText(MainActivity.this, "Регистрация провалена", Toast.LENGTH_SHORT).show();
}
}
});
}
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mAuth.signInWithCredential(credential)
.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, "signInWithCredential:success");
FirebaseUser user = mAuth.getCurrentUser();
updateUI(user);
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "signInWithCredential:failure", task.getException());
Toast.makeText(MainActivity.this, "Authentication Failed.", Toast.LENGTH_SHORT).show();
updateUI(null);
}
// ...
}
});
}
private void updateUI(FirebaseUser user) {
if (user != null) {
mStatusTextView.setText( user.getEmail());
mDetailTextView.setText( user.getUid());
findViewById(R.id.btn_google).setVisibility(View.GONE);
findViewById(R.id.btn_vk).setVisibility(View.VISIBLE);
} else {
mStatusTextView.setText("Вышел");
mDetailTextView.setText(null);
findViewById(R.id.btn_google).setVisibility(View.VISIBLE);
findViewById(R.id.btn_vk).setVisibility(View.GONE);
}
}
}
But the error in the logs:
2019-06-22 17:55:42.652 29327-23222/? E/AudioSource: Stop listening is
called on already closed AudioSource 2019-06-22 17:55:43.240
2093-2616/? E/TouchFilter: setTouchFilter LOG Enable prameter: 0
2019-06-22 17:55:43.554 31234-31234/com.anntoxa.foodforyou
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.anntoxa.foodforyou, PID: 31234
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.anntoxa.foodforyou/com.anntoxa.foodforyou.MainActivity}:
java.lang.NullPointerException: Attempt to invoke virtual method 'void
android.widget.TextView.setText(java.lang.CharSequence)' on a null
object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2805)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2883)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void
android.widget.TextView.setText(java.lang.CharSequence)' on a null
object reference
at com.anntoxa.foodforyou.MainActivity.updateUI(MainActivity.java:176)
at com.anntoxa.foodforyou.MainActivity.onCreate(MainActivity.java:51)
at android.app.Activity.performCreate(Activity.java:7023)
at android.app.Activity.performCreate(Activity.java:7014)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2758)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2883) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6523) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857) 
2019-06-22 17:55:43.564 2093-2156/? E/ActivityManager_tangan: app
crash,kill it 2019-06-22 17:55:43.569 384-384/? E/lowmemorykiller:
Error writing /proc/31234/oom_score_adj; errno=22

You should move this block:
mDetailTextView = (TextView) findViewById(R.id.mDetailTextView);
mStatusTextView = (TextView) findViewById(R.id.mStatusTextView);
before calling updateUI in onCreate

Related

FirebaseAuth.getInstance() throwing exception java.lang.NoSuchMethodError

I'm implementing google sign-in using firebase, when I'm getting instance of firebaseauth class then its throws an exception,
java.lang.NoSuchMethodError
but my code is copied as it is from documentation(https://firebase.google.com/docs/auth/android/google-signin). Please help.
code:
public class LoginActivity extends AppCompatActivity {
private static final String TAG = "LoginActivity_Firebase";
private static final int RC_SIGN_IN = 9001;
private FirebaseAuth mAuth;
private GoogleSignInClient mGoogleSignInClient;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mAuth = FirebaseAuth.getInstance(); //this line is shown as error
//finding button and setting click listener
findViewById(R.id.signInButton).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
signIn();
}
});
}
void setupGoogleSignIn(){
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
}
private void signIn() {
setupGoogleSignIn();
Intent signInIntent = mGoogleSignInClient.getSignInIntent(); //getting signIn intent from googleclient
startActivityForResult(signInIntent, RC_SIGN_IN);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = task.getResult(ApiException.class);
Log.d(TAG, "firebaseAuthWithGoogle: " + account.getIdToken());
firebaseAuthWithGoogle(account.getIdToken());
} catch (ApiException e) {
// Google Sign In failed, update UI appropriately
Log.w(TAG, "Google sign in failed", e);
}
}
}
private void firebaseAuthWithGoogle(String idToken) {
Log.d(TAG, "firebaseAuthWithGoogle: called");
AuthCredential credential = GoogleAuthProvider.getCredential(idToken, null);
mAuth.signInWithCredential(credential)
.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, "signInWithCredential:success");
FirebaseUser user = mAuth.getCurrentUser();
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "signInWithCredential:failure", task.getException());
}
}
});
}
}
The complete Logcat
Process: com.recipeapp.marathi, PID: 13369
java.lang.NoSuchMethodError: No virtual method setTokenProvider(Lcom/google/firebase/internal/InternalTokenProvider;)V in class Lcom/google/firebase/FirebaseApp; or its super classes (declaration of 'com.google.firebase.FirebaseApp' appears in /data/app/com.recipeapp.marathi-3W2YRoeaSMJdnEELQ9KFbw==/base.apk)
at com.google.firebase.auth.FirebaseAuth.zza(Unknown Source:22)
at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source:4)
at com.recipeapp.marathi.activities.LoginActivity.onCreate(LoginActivity.java:37)
at android.app.Activity.performCreate(Activity.java:7964)
at android.app.Activity.performCreate(Activity.java:7953)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3472)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3636)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:140)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:100)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2222)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:228)
at android.app.ActivityThread.main(ActivityThread.java:7782)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:981)
dependencies:
//auth firebase
implementation platform('com.google.firebase:firebase-bom:26.7.0')
implementation "com.google.firebase:firebase-database:$firebase_google_version"
implementation "com.google.firebase:firebase-auth:$firebase_google_version"
implementation "com.google.android.gms:play-services-auth:$firebase_google_version"
implementation "com.google.firebase:firebase-ads:$firebase_google_version"
implementation 'com.firebaseui:firebase-ui-database:7.1.1'
pls help me fix this.

Failed to get FirebaseDatabase instance: Specify DatabaseURL within FirebaseApp or from your getInstance() call [duplicate]

I have this mistake when I log in with Google
com.google.firebase.database.DatabaseException: Failed to get FirebaseDatabase instance: Specify DatabaseURL within FirebaseApp or from your getInstance() call.
at com.google.firebase.database.FirebaseDatabase.getInstance(com.google.firebase:firebase-database##16.0.5:114)
at com.google.firebase.database.FirebaseDatabase.getInstance(com.google.firebase:firebase-database##16.0.5:71)
at pl.cyfrogen.budget.ui.signin.SignInActivity.updateUI(SignInActivity.java:145)
at pl.cyfrogen.budget.ui.signin.SignInActivity.access$400(SignInActivity.java:41)
at pl.cyfrogen.budget.ui.signin.SignInActivity$3.onComplete(SignInActivity.java:130)
at com.google.android.gms.tasks.zzj.run(Unknown Source:4)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:8167)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
enter image description here
public class SignInActivity extends AppCompatActivity {
private static final int RC_SIGN_IN = 123;
private FirebaseAuth mAuth;
private GoogleSignInClient mGoogleSignInClient;
private TextView errorTextView;
private SignInButton signInButton;
private View progressView;
private TextView privacyPolicyTextView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_signin);
progressView = findViewById(R.id.progress_view);
mAuth = FirebaseAuth.getInstance();
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
signInButton = findViewById(R.id.sign_in_button);
signInButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
signIn();
signInButton.setEnabled(false);
errorTextView.setText("");
}
});
privacyPolicyTextView = findViewById(R.id.privacy_policy_text_view);
SpannableStringBuilder spanTxt = new SpannableStringBuilder(
"By signing in, you are indicating that you have read and agree to the ");
spanTxt.append("privacy policy");
spanTxt.setSpan(new ClickableSpan() {
#Override
public void onClick(#NonNull View widget) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse(Links.PRIVACY_POLICY_LINK));
startActivity(browserIntent);
}
}, spanTxt.length() - "privacy policy".length(), spanTxt.length(), 0);
privacyPolicyTextView.setMovementMethod(LinkMovementMethod.getInstance());
privacyPolicyTextView.setText(spanTxt, TextView.BufferType.SPANNABLE);
errorTextView = findViewById(R.id.error_textview);
}
#Override
public void onStart() {
super.onStart();
showProgressView();
FirebaseUser currentUser = mAuth.getCurrentUser();
updateUI(currentUser);
}
private void signIn() {
showProgressView();
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
GoogleSignInAccount account = task.getResult(ApiException.class);
firebaseAuthWithGoogle(account);
} catch (ApiException e) {
e.printStackTrace();
hideProgressView();
loginError("Google sign in failed.");
}
}
}
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseUser user = mAuth.getCurrentUser();
updateUI(user);
} else {
loginError("Firebase auth failed.");
hideProgressView();
}
}
});
}
private void updateUI(FirebaseUser currentUser) {
if (currentUser == null) {
progressView.setVisibility(View.GONE);
return;
}
showProgressView();
final DatabaseReference userReference = FirebaseDatabase.getInstance().getReference("users").child(currentUser.getUid());
userReference.addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
User user = dataSnapshot.getValue(User.class);
if (user != null) {
startActivity(new Intent(SignInActivity.this, MainActivity.class));
finish();
} else {
runTransaction(userReference);
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
loginError("Firebase fetch user data failed.");
hideProgressView();
}
});
}
private void loginError(String text) {
errorTextView.setText(text);
signInButton.setEnabled(true);
}
private void runTransaction(DatabaseReference userReference) {
showProgressView();
userReference.runTransaction(new Transaction.Handler() {
#Override
public Transaction.Result doTransaction(MutableData mutableData) {
User user = mutableData.getValue(User.class);
if (user == null) {
mutableData.setValue(new User());
return Transaction.success(mutableData);
}
return Transaction.success(mutableData);
}
#Override
public void onComplete(DatabaseError databaseError, boolean committed,
DataSnapshot dataSnapshot) {
if (committed) {
startActivity(new Intent(SignInActivity.this, MainActivity.class));
finish();
} else {
errorTextView.setText("Firebase create user transaction failed.");
hideProgressView();
}
}
});
}
private void showProgressView() {
progressView.setVisibility(View.VISIBLE);
}
private void hideProgressView() {
progressView.setVisibility(View.GONE);
}
#Override
public void onBackPressed() {
moveTaskToBack(true);
}
}
It looks like you're configuring Firebase without specifying the URL of the Realtime Database. There are a few reasons this could be happening:
If you are providing the configuration data in code, be sure to call setDatabaseUrl on your options.
This is especially likely when your database instance is hosted in another region than the (default) US one.
If you are providing the configuration data through the GoogleServices.json file, be sure to download a new version of that file after you create the database in the Firebase console.
This is a new requirement (since a few weeks ago) as the Realtime Database is now created on-demand (instead of auto-created when the project is created), so that you can pick in what region it's created.
Seems like you didn't connect your app to firebase.
You should:
connect your app to firebase
add Firebase Authentication to your project
You are also using Firebase Database. Connect it to your project.
After all, change this code
final DatabaseReference userReference = FirebaseDatabase.getInstance().getReference("users").child(currentUser.getUid());
to this:
final DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
final DatabaseReference userReference = rootRef.child("users").child(currentUser.getUid());
To conclude, as Frank mentioned, do not forget to download your google-services.json file and add it into the module (app-level) directory of your app

Multiple Auth Providers Android Firebase

I have LoginActivity with Email/password login, facebook, google authentication. It works separately but if I create account with google, I can't login with facebook.
Login activity code:
public class LoginActivity extends AppCompatActivity {
private Button mLogin,mRegister;
private int RC_SIGN_IN =0;
private EditText mEmail, mPassword;
public FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener firebaseAuthStateListener;
CallbackManager callbackManager;
private LoginButton loginButton;
private static final String EMAIL = "email";
private TextView facebookRegister;
private SignInButton googleSignIn;
GoogleSignInClient mGoogleSignInClient;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Intent intent = new Intent(LoginActivity.this, LoginTest.class);
startActivity(intent);
//FACEBOOK
mAuth = FirebaseAuth.getInstance();
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(getApplication());
callbackManager = CallbackManager.Factory.create();
// Configure sign-in to request the user's ID, email address, and basic
// profile. ID and basic profile are included in DEFAULT_SIGN_IN.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
// Build a GoogleSignInClient with the options specified by gso.
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
googleSignIn = findViewById(R.id.sign_in_button);
googleSignIn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.sign_in_button:
signIn();
break;
// ...
}
}
});
firebaseAuthStateListener= new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if(user !=null){
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
finish();
return;
}
}
};
loginButton = findViewById(R.id.login_button);
loginButton.setReadPermissions(Arrays.asList(EMAIL));
mLogin = (Button) findViewById(R.id.login);
mEmail = (EditText) findViewById(R.id.email);
mPassword=(EditText) findViewById(R.id.password);
mRegister=(Button)findViewById(R.id.register);
// Callback registration
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
// App code
handleFacebookToken(loginResult.getAccessToken());
//fill database
}
#Override
public void onCancel() {
// App code
}
#Override
public void onError(FacebookException exception) {
// App code
}
});
mLogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
logInEmailPassword();
}
});
mRegister.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(LoginActivity.this, RegistrationActivity.class);
startActivity(intent);
finish();
return;
}
});
}
#Override
protected void onStart() {
super.onStart();
GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
mAuth.addAuthStateListener(firebaseAuthStateListener);
}
#Override
protected void onStop() {
super.onStop();
mAuth.removeAuthStateListener(firebaseAuthStateListener);
}
private void logInEmailPassword() {
String email = mEmail.getText().toString();
String password = mPassword.getText().toString();
if(email.isEmpty()){
Toast.makeText(LoginActivity.this, "Wrong email", Toast.LENGTH_SHORT).show();
mEmail.setError("Enter email!");
};
if(password.isEmpty()){
mPassword.setError("Enter password!");
Toast.makeText(LoginActivity.this, "Wrong password", Toast.LENGTH_SHORT).show();
}
if(!email.isEmpty() && !password.isEmpty()){
AuthCredential credential = EmailAuthProvider.getCredential(email, password);
linkWithCredential(credential);
}
}
private void handleFacebookToken(AccessToken token) {
AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
linkWithCredential(credential);
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
// The Task returned from this call is always completed, no need to attach
// a listener.
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
}
}
private void signIn() {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
}
private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
FirebaseGoogleAuth(account);
// Signed in successfully, show authenticated UI.
} catch (ApiException e) {
// The ApiException status code indicates the detailed failure reason.
// Please refer to the GoogleSignInStatusCodes class reference for more information.
Log.w("myLog", "signInResult:failed code=" + e.getStatusCode());;
}
}
private void FirebaseGoogleAuth(GoogleSignInAccount account) {
AuthCredential authCredential = GoogleAuthProvider.getCredential(account.getIdToken(),null);
linkWithCredential(authCredential);
}
private void linkWithCredential(AuthCredential credential){
mAuth = FirebaseAuth.getInstance()
//mAuth.getCurrentUser().linkWithCredential(credential)
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Log.d("myLog", "linkWithCredential:success");
FirebaseUser user = task.getResult().getUser();
updateUI(user);
} else {
Log.w("myLog", "linkWithCredential:failure", task.getException());
Toast.makeText(LoginActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
LoginManager.getInstance().logOut();
updateUI(null);
}
// ...
}
});
}
}
I've followed https://firebase.google.com/docs/auth/android/account-linking?authuser=0 tutorial but I stuck at linkWithCredential.
Can you help me fix that issue? Thanks
The problem if that user exists in Firebase Authentication already and is assigned to GoogleAuth i cant login with Facebook.
It works vice versa, if facebook user exists in firebase and i login with google it overrides that user.
Register ---- logout ---- login
Google --->>>>>>>>>>>>>>>>Facebook >>>>dont work
Facebook--->>>>>>>>>>>>>>>Google >>>>> works

firebase phone number authentication getting null reference

I am trying to create a phone number logging section in my application so that the user can log in using the phone number. I am trying to run my application on the physical device when I try to login using the phone number and received an error says the null reference. I have searched for the solution all over the internet but didn't get any proper solution to remove this error. I have allowed the phone authentication in firebase still, I am getting the error. I have used the country picker in my activity to get the country code and it works file.
Error occurs in
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phonestring,
60,
TimeUnit.SECONDS,
Phoneactivity.this,
mCallbacks
);
Phoneactivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_phoneactivity);
mAuth = FirebaseAuth.getInstance();
initalization();
phonenumbermethod();
emailloginmethod();
}
private void emailloginmethod() {
emaillogin.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(),Loginactivity.class);
startActivity(intent);
}
});
}
private void phonenumbermethod() {
if(REQUEST.equals("phone")){
submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
REQUEST = "OTP";
String phonenumberstring = phone.getText().toString();
String countrycode = ccp.getSelectedCountryCodeWithPlus();
phonestring = countrycode + phonenumberstring;
//Toast.makeText(getApplicationContext(),phonestring,Toast.LENGTH_SHORT).show();
verificationcodesend();
}
});
}else{
submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
REQUEST = "phone";
otpstring = otp.getText().toString();
otpmethod();
}
});
}
}
private void otpmethod() {
if (TextUtils.isEmpty(otpstring)){
Toast.makeText(getApplicationContext(),"Please enter the verification code", Toast.LENGTH_SHORT).show();
}else{
loadingBar.setTitle("Verification code");
loadingBar.setMessage("Please wait...");
loadingBar.setCanceledOnTouchOutside(false);
loadingBar.show();
PhoneAuthCredential credential = PhoneAuthProvider.getCredential(mVerificationId, otpstring);
signInWithPhoneAuthCredential(credential);
}
}
private void verificationcodesend() {
if(TextUtils.isEmpty(phonestring)){
Toast.makeText(getApplicationContext(),"Please enter phone number",Toast.LENGTH_SHORT).show();
}else{
loadingBar.setTitle("Phone verification");
loadingBar.setMessage("Please wait till we verify your account");
loadingBar.setCanceledOnTouchOutside(false);
loadingBar.show();
Log.i("phoneactivity",phonestring);
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phonestring,
60,
TimeUnit.SECONDS,
Phoneactivity.this,
mCallbacks
);
}
mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
#Override
public void onVerificationCompleted(#NonNull PhoneAuthCredential phoneAuthCredential) {
signInWithPhoneAuthCredential(phoneAuthCredential);
}
#Override
public void onVerificationFailed(#NonNull FirebaseException e) {
loadingBar.dismiss();
Toast.makeText(getApplicationContext(),"Please enter the correct phone number", Toast.LENGTH_SHORT).show();
}
#Override
public void onCodeSent(#NonNull String verificationId,
#NonNull PhoneAuthProvider.ForceResendingToken token) {
loadingBar.dismiss();
mVerificationId = verificationId;
mResendToken = token;
Toast.makeText(getApplicationContext(),"Verification code has been send", Toast.LENGTH_SHORT).show();
otpnumber.setVisibility(View.VISIBLE);
phonenumber.setVisibility(View.GONE);
}
};
}
private void signInWithPhoneAuthCredential(PhoneAuthCredential credential) {
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
loadingBar.dismiss();
sendusertomainActivity();
Toast.makeText(getApplicationContext(),"welcome",Toast.LENGTH_SHORT).show();
} else {
String msg = task.getException().toString();
Toast.makeText(getApplicationContext(),"Error: "+ msg, Toast.LENGTH_SHORT).show();
}
}
});
}
private void sendusertomainActivity() {
Intent intent = new Intent(getApplicationContext(),HomeActivity.class);
startActivity(intent);
}
error: null reference
java.lang.NullPointerException: null reference
at com.google.android.gms.common.internal.Preconditions.checkNotNull(Unknown Source:2)
at com.google.firebase.auth.PhoneAuthProvider.verifyPhoneNumber(com.google.firebase:firebase-auth##19.2.0:9)
at com.nanb.Alpha.Phoneactivity.verificationcodesend(Phoneactivity.java:109)
at com.nanb.Alpha.Phoneactivity.access$300(Phoneactivity.java:28)
at com.nanb.Alpha.Phoneactivity$2.onClick(Phoneactivity.java:72)
at android.view.View.performClick(View.java:6608)
at android.view.View.performClickInternal(View.java:6585)
at android.view.View.access$3100(View.java:785)
at android.view.View$PerformClick.run(View.java:25921)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6864)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
update
2020-03-15 21:03:00.382 30384-30384/com.nanb.Alpha I/phoneactivity: +919771553694
You're not initializing mCallback before passing it into verifyPhoneNumber, which is what the null check is complaining about.
To fix it, move the mCallbacks = new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {... before the call to verifyPhoneNumber.

Android Studio - Firebase returns null when trying to sign facebook or google

When I'm trying to sign in into Firebase using Facebook or Google, my app crashes because its not creating a new user to the Firebase using CreateNewUser().
Logcat:-
05-10 09:11:58.180 16986-16986/com.example.sefi.authenticationproject E/VideoAdapter: onCreateViewHolder() >>
05-10 09:11:58.191 16986-16986/com.example.sefi.authenticationproject E/VideoAdapter: onCreateViewHolder() <<
05-10 09:11:58.193 16986-16986/com.example.sefi.authenticationproject E/VideoAdapter: onBindViewHolder() >> 0
05-10 09:11:58.203 16986-16986/com.example.sefi.authenticationproject E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.sefi.authenticationproject, PID: 16986
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
at com.example.sefi.authenticationproject.adapter.VideoAdapter.onBindViewHolder(VideoAdapter.java:114)
at com.example.sefi.authenticationproject.adapter.VideoAdapter.onBindViewHolder(VideoAdapter.java:32)
at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6482)
at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:6515)
at android.support.v7.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:5458)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5724)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5563)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5559)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2229)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1556)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1516)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:608)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3693)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3410)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3962)
at android.view.View.layout(View.java:18799)
at android.view.ViewGroup.layout(ViewGroup.java:5952)
at android.support.constraint.ConstraintLayout.onLayout(ConstraintLayout.java:1855)
at android.view.View.layout(View.java:18799)
at android.view.ViewGroup.layout(ViewGroup.java:5952)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at android.view.View.layout(View.java:18799)
at android.view.ViewGroup.layout(ViewGroup.java:5952)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1741)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
at android.view.View.layout(View.java:18799)
at android.view.ViewGroup.layout(ViewGroup.java:5952)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
at com.android.internal.policy.DecorView.onLayout(DecorView.java:822)
at android.view.View.layout(View.java:18799)
at android.view.ViewGroup.layout(ViewGroup.java:5952)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2634)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2350)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1509)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7051)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:927)
at android.view.Choreographer.doCallbacks(Choreographer.java:702)
at android.view.Choreographer.doFrame(Choreographer.java:638)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:913)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
LogInActivity.java
public class LogInActivity extends Activity {
public static final String TAG = "LogInActivity";
private static final int RC_GOOGLE_SIGN_IN = 1001;
private FirebaseAuth mAuth;
private FirebaseAuth.AuthStateListener mAuthListener;
private CallbackManager mCallbackManager;
private AccessTokenTracker mAccessTokenTracker;
private GoogleSignInClient mGoogleSignInClient;
private EditText mEmail;
private EditText mPass;
private TextView mStatus;
private boolean mIsSignup;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.log_in_activity);
mEmail = findViewById(R.id.email_id);
mPass = findViewById(R.id.password_id);
mStatus = findViewById(R.id.status_id);
firebaseAuthenticationInit();
googleSigninInit();
facebookLoginInit();
}
#Override
protected void onStart() {
Log.e(TAG, "onStart() >>");
super.onStart();
mAuth.addAuthStateListener(mAuthListener);
updateLoginStatus("N.A");
Log.e(TAG, "onStart() <<");
}
#Override
protected void onStop() {
Log.e(TAG, "onStop() >>");
super.onStop();
if (mAuthListener != null) {
mAuth.removeAuthStateListener(mAuthListener);
}
Log.e(TAG, "onStop() <<");
}
public void onEmailPasswordAuthClick(View V) {
Log.e(TAG, "onEmailPasswordAuthClick() >>");
String email = mEmail.getText().toString();
String pass = mPass.getText().toString();
Task<AuthResult> authResult;
boolean canContinue = checkIfEmailOrPasswordIsRequired(email, pass);
if (canContinue == true)
{
switch (V.getId()) {
case R.id.sign_in_id:
//Email / Password sign-in
authResult = mAuth.signInWithEmailAndPassword(email, pass);
moveToNextScreenAfterValidation(authResult);
mIsSignup = false;
break;
case R.id.sign_up_id:
//Email / Password sign-up
authResult = mAuth.createUserWithEmailAndPassword(email, pass);
mIsSignup = true;
moveToNextScreenAfterValidation(authResult);
break;
default:
return;
}
authResult.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
Log.e(TAG, "Email/Pass Auth: onComplete() >> " + task.isSuccessful());
if (mIsSignup) {
createNewUser();
}
if (!task.isSuccessful())
{
Toast.makeText(LogInActivity.this, "User is already in use or there is a temporary problem", Toast.LENGTH_LONG).show();
}
updateLoginStatus(task.isSuccessful() ? "N.A" : task.getException().getMessage());
Log.e(TAG, "Email/Pass Auth: onComplete() <<");
}
});
}
Log.e(TAG, "onEmailPasswordAuthClick() <<");
}
public void signInAnonymously(View v) {
mAuth.signInAnonymously()
.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, "signInAnonymously:success");
FirebaseUser user = mAuth.getCurrentUser();
Intent intent = new Intent(LogInActivity.this,StandupPlayerMain.class);
startActivity(intent);
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "signInAnonymously:failure", task.getException());
Toast.makeText(LogInActivity.this, "Skip sign up failed", Toast.LENGTH_LONG).show();
}
}
});
}
public void onForgetPasswordClick(View V)
{
Intent intent = new Intent(LogInActivity.this,ForgotMyPassword.class);
startActivity(intent);
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.e(TAG, "onActivityResult () >>");
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_GOOGLE_SIGN_IN) {
//Google Login...
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
// Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = task.getResult(ApiException.class);
firebaseAuthWithGoogle(account);
} catch (ApiException e) {
// Google Sign In failed, update UI appropriately
Log.e(TAG, "Google sign in failed", e);
Toast.makeText(LogInActivity.this, "Google signing in falied", Toast.LENGTH_LONG).show();
// ...
}
}
mCallbackManager.onActivityResult(requestCode, resultCode, data);
Log.e(TAG, "onActivityResult () <<");
}
private void facebookLoginInit() {
Log.e(TAG, "facebookLoginInit() >>");
mCallbackManager = CallbackManager.Factory.create();
LoginButton loginButton = findViewById(R.id.login_button);
loginButton.setReadPermissions("email", "public_profile");
loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
Log.e(TAG, "facebook:onSuccess () >>" + loginResult);
Log.e(TAG, "look for me");
createNewUser();
handleFacebookAccessToken(loginResult.getAccessToken());
Log.e(TAG, "facebook:onSuccess () <<");
}
#Override
public void onCancel() {
Log.e(TAG, "facebook:onCancel() >>");
updateLoginStatus("Facebook login canceled");
Log.e(TAG, "facebook:onCancel() <<");
}
#Override
public void onError(FacebookException error) {
Log.e(TAG, "facebook:onError () >>" + error.getMessage());
Toast.makeText(LogInActivity.this, "Facebook log in failed", Toast.LENGTH_LONG).show();
updateLoginStatus(error.getMessage());
Log.e(TAG, "facebook:onError <<");
}
});
mAccessTokenTracker = new AccessTokenTracker() {
#Override
protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken,AccessToken currentAccessToken) {
Log.e(TAG, "facebook:inside Token change <<");
if (currentAccessToken == null)
{
mAuth.signOut();
updateLoginStatus("Facebook signuout");
}
Log.e(TAG,"onCurrentAccessTokenChanged() >> currentAccessToken="+
(currentAccessToken !=null ? currentAccessToken.getToken():"Null") +
" ,oldAccessToken=" +
(oldAccessToken !=null ? oldAccessToken.getToken():"Null"));
}
};
Log.e(TAG, "facebookLoginInit() <<");
}
private void handleFacebookAccessToken(AccessToken token) {
Log.e(TAG, "handleFacebookAccessToken () >>" + token.getToken());
AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
Log.e(TAG, "Facebook: onComplete() >> " + task.isSuccessful());
if(task.isSuccessful()==true)
{
Intent intent = new Intent(LogInActivity.this,StandupPlayerMain.class);
startActivity(intent);
}
updateLoginStatus(task.isSuccessful() ? "N.A" : task.getException().getMessage());
Log.e(TAG, "Facebook: onComplete() <<");
}
});
Log.e(TAG, "handleFacebookAccessToken () <<");
}
private void firebaseAuthenticationInit() {
Log.e(TAG, "firebaseAuthenticationInit() >>");
//Obtain reference to the current authentication
mAuth = FirebaseAuth.getInstance();
FirebaseUser user = mAuth.getCurrentUser();
if (user != null)
{
Intent intent = new Intent(LogInActivity.this,StandupPlayerMain.class);
startActivity(intent);
}
mAuthListener = new FirebaseAuth.AuthStateListener() {
#Override
public void onAuthStateChanged(#NonNull FirebaseAuth firebaseAuth) {
Log.e(TAG, "onAuthStateChanged() >>");
updateLoginStatus("N.A");
Log.e(TAG, "onAuthStateChanged() <<");
}
};
Log.e(TAG, "firebaseAuthenticationInit() <<");
}
private void googleSigninInit() {
Log.e(TAG, "googleSigninInit() >>" );
// Configure Google Sign In
GoogleSignInOptions gso = new GoogleSignInOptions
.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestProfile()
.requestEmail()
.build();
// Build a GoogleSignInClient with the options specified by gso.
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
findViewById(R.id.google_sign_in_button).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Log.e(TAG, "look for me" + mAuth.getCurrentUser().toString());
onGooglesignIn();
}
});
Log.e(TAG, "googleSigninInit() <<" );
}
private void onGooglesignIn() {
Log.e(TAG, "onGooglesignIn() >>" );
createNewUser();
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_GOOGLE_SIGN_IN);
Log.e(TAG, "onGooglesignIn() <<" );
}
private boolean checkIfEmailOrPasswordIsRequired(String email,String password)
{
boolean result = true;
if (email.length() == 0)
{
result = false;
Toast.makeText(LogInActivity.this, "Email is missing", Toast.LENGTH_LONG).show();
}
else if (password.length() == 0)
{
result = false;
Toast.makeText(LogInActivity.this, "Password is missing", Toast.LENGTH_LONG).show();
}
return result;
}
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
Log.e(TAG, "firebaseAuthWithGoogle() >>" + acct.getId());
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
updateLoginStatus(task.isSuccessful() ? "N.A" : task.getException().getMessage());
Log.e(TAG, "look for me");
Intent intent = new Intent(LogInActivity.this,StandupPlayerMain.class);
startActivity(intent);
}
});
Log.e(TAG, "firebaseAuthWithGoogle() <<");
}
private void moveToNextScreenAfterValidation(Task<AuthResult> authResult)
{
Log.e(TAG, "emailPasswordVaildation () >>");
authResult.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
#Override
public void onComplete(#NonNull Task<AuthResult> task) {
Log.e(TAG, "emailPasswordVaildation outside if");
if(task.isSuccessful() == true)
{
Log.e(TAG, "emailPasswordVaildation inside if");
//createNewUser();
Intent intent = new Intent(LogInActivity.this,StandupPlayerMain.class);
intent.putExtra("User Info",mAuth.getCurrentUser().getUid());
startActivity(intent);
}
}
});
Log.e(TAG, "emailPasswordVaildation () <<");
}
private void updateLoginStatus(String details) {
FirebaseUser user = mAuth.getCurrentUser();
if (user == null) {
mStatus.setText("SIGNED-OUT \ndetails:" + details);
} else {
mStatus.setText("SIGNED-IN\nname:" + user.getDisplayName() +
"\nemail:" + user.getEmail() +
"\nuid:" + user.getUid() +
"\ndetails:" + details);
}
}
private void createNewUser() {
Log.e(TAG, "createNewUser() >>");
FirebaseUser fbUser = mAuth.getCurrentUser();
DatabaseReference userRef = FirebaseDatabase.getInstance().getReference("Users");
if (fbUser == null) {
Log.e(TAG, "createNewUser() << Error user is null");
return;
}
Log.e(TAG,userRef.toString());
userRef.child(fbUser.getUid()).setValue(new User(fbUser.getEmail(),0,null));
Log.e(TAG, "createNewUser() <<");
}
}
It's a bug in adapter not in current activity, I guess.
Your logs says:-
Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference at com.example.sefi.authenticationproject.adapter.VideoAdapter.onBindViewHolder(VideoAdapter.java:114)
Your issue is with activity/fragment where you may be using an adapter "VideoAdapter" and there can be some "view" which is not defined.
If still issue persists, Please use Debugger and run code line by line, and provide more detailed and specific issue.

Categories

Resources