异常java.lang.StackOverflowError:堆栈大小8MB [英] Exception java.lang.StackOverflowError: stack size 8MB

查看:39
本文介绍了异常java.lang.StackOverflowError:堆栈大小8MB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此错误,我无法真正弄清楚它是什么.我认为这是一个循环,但我找不到它.您能帮我找到并安排吗?我不确定它在此屏幕上,但我不确定.在Firebase Auth中,匹配问题的页面正在访问google.谢谢大家

I have this error and I can not really figure out what it is. I think it's a loop but I can not find it. Can you help me find and arrange it? I think it's in this screen though I'm not entirely sure. the page where the prolema match is accessing google in Firebase Auth. thank you all

我知道还有其他类似的问题,但是我没有找到答案

I know there are other questions similar to this, but I did not find my answer

Exception java.lang.StackOverflowError: stack size 8MB com.google.android.gms.internal.zzbtg.zzaz (zzbtg.java)

这是我发现问题的活动

public class GoogleSignIn extends BaseActivity implements
    GoogleApiClient.OnConnectionFailedListener,
    View.OnClickListener {

private static final String TAG = "GoogleActivity";
private static final int RC_SIGN_IN = 9001;

// [START declare_auth]
private FirebaseAuth mAuth;
// [END declare_auth]

// [START declare_auth_listener]
private FirebaseAuth.AuthStateListener mAuthListener;
// [END declare_auth_listener]

private GoogleApiClient mGoogleApiClient;
private DatabaseReference mDatabase;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.auth_google_sign_in);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    mDatabase = FirebaseDatabase.getInstance().getReference();
    toolbar.setTitleTextColor(Color.WHITE);
    toolbar.setNavigationIcon(getResources().getDrawable(R.mipmap.ic_arrow_back_white_24dp));
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //What to do on back clicked
            onBackPressed();
        }
    });

    // Button listeners
    findViewById(R.id.sign_in_button).setOnClickListener(this);

    // [START config_signin]
    // Configure Google Sign In
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.default_web_client_id))
            .requestEmail()
            .build();
    // [END config_signin]

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();

    // [START initialize_auth]
    mAuth = FirebaseAuth.getInstance();
    // [END initialize_auth]

    // [START auth_state_listener]
    mAuthListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                // User is signed in
                Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid());
            } else {
                // User is signed out
                Log.d(TAG, "onAuthStateChanged:signed_out");
            }
            // [START_EXCLUDE]

            // [END_EXCLUDE]
        }
    };
    // [END auth_state_listener]
}

// [START on_start_add_listener]
@Override
public void onStart() {
    super.onStart();
    mAuth.addAuthStateListener(mAuthListener);
}
// [END on_start_add_listener]

// [START on_stop_remove_listener]
@Override
public void onStop() {
    super.onStop();
    if (mAuthListener != null) {
        mAuth.removeAuthStateListener(mAuthListener);
    }
}
// [END on_stop_remove_listener]

// [START onactivityresult]
@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) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        if (result.isSuccess()) {
            // Google Sign In was successful, authenticate with Firebase
            GoogleSignInAccount account = result.getSignInAccount();
            firebaseAuthWithGoogle(account);
        } else {
            Toast.makeText(GoogleSignIn.this, getString(R.string.auth_failed), Toast.LENGTH_LONG).show();

        }
    }
}
// [END onactivityresult]

// [START auth_with_google]
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
    Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId());
    // [START_EXCLUDE silent]
    showProgressDialog();
    // [END_EXCLUDE]

    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
    mAuth.signInWithCredential(credential)
            .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {




                    // 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()) {
                        Toast.makeText(GoogleSignIn.this, "Authentication failed", Toast.LENGTH_SHORT).show();
                    }
                    // [START_EXCLUDE]
                    hideProgressDialog();
                    onAuthSuccess(task.getResult().getUser());
                    // [END_EXCLUDE]

                    Intent intent = new Intent(GoogleSignIn.this, HomeActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    startActivity(intent);
                }
            });
}
// [END auth_with_google]

// [START signin]
public void signIn() {
    Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
    startActivityForResult(signInIntent, RC_SIGN_IN);
}
// [END signin]

@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {

    Toast.makeText(this, "Google Play Services error.", Toast.LENGTH_SHORT).show();
}

@Override
public void onClick(View v) {
    int i = v.getId();
    if (i == R.id.sign_in_button) {
        signIn();
    }
}
private void onAuthSuccess(FirebaseUser user) {

    SharedPreferences.Editor sharedPreferences = getSharedPreferences("GOOGLE_LOGIN", MODE_PRIVATE).edit();
    sharedPreferences.putString("google", "true").apply();

    mDatabase.child("user-profile").child(user.getUid()).child("username").setValue(user.getDisplayName());
    mDatabase.child("user-profile").child(user.getUid()).child("photoUrl").setValue(user.getPhotoUrl());
    mDatabase.child("user-profile").child(user.getUid()).child("uid").setValue(user.getUid());
    mDatabase.child("user-profile").child(user.getUid()).child("email").setValue(user.getEmail());

}

}

推荐答案

问题是此语句:

mDatabase.child("user-profile").child(user.getUid()).child("photoUrl")
    .setValue(user.getPhotoUrl());

getPhotoUrl()返回 Uri .这不是

getPhotoUrl() returns a Uri. That is not one of the object types supported by setValue(). You should instead store getPhotoUrl().toString().

这篇关于异常java.lang.StackOverflowError:堆栈大小8MB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆