Cannot cast to com.google.android.gms.common.api.GoogleApiClient$OnConnectionFailedListener

882 Views Asked by At

I am trying to insert Google signin in an app but I have the following error:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gf.globalflow/com.gf.globalflow.LoginTienda}: java.lang.ClassCastException: com.gf.globalflow.LoginTienda cannot be cast to com.google.android.gms.common.api.GoogleApiClient$OnConnectionFailedListener Caused by: java.lang.ClassCastException: com.gf.globalflow.LoginTienda cannot be cast to com.google.android.gms.common.api.GoogleApiClient$OnConnectionFailedListener at com.gf.globalflow.LoginTienda.onCreate(LoginTienda.java:108)

I know this error can be fixed implementing the OnConnectionFailedListener method but I do it and the error is not fixed.

The code:

glogin = (SignInButton) findViewById(R.id.btngoogle);

GoogleSignInOptions gSignInOptions = new 

GoogleSignInOptions.
Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).
requestEmail().
build();

final GoogleApiClient gApiClient = new GoogleApiClient //this is the line of the error
            .Builder(this)
            .enableAutoManage(this, 
            (GoogleApiClient.OnConnectionFailedListener) this)
            .addOnConnectionFailedListener(new 
            GoogleApiClient.OnConnectionFailedListener()
            {
                @Override
                public void onConnectionFailed(@NonNull ConnectionResult 
                connectionResult)
                {
                    Toast.makeText(getApplicationContext(),"La conexión al 
                    cliente api de Google ha fallado",
                    Toast.LENGTH_LONG).show();
                }
            })
            .addApi(Auth.GOOGLE_SIGN_IN_API,gSignInOptions)
            .build();

        glogin.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                if(v.getId() == R.id.btngoogle)
                {
                    gSignIn();
                }
            }
        }
        );

public void gSignIn()
{
    Intent i = Auth.GoogleSignInApi.getSignInIntent(gApiClient);
    startActivityForResult(i,CODIGO_REQ);

}

public void HandleResult(GoogleSignInResult gSignInResult)
{
    if(gSignInResult.isSuccess())
    {
        GoogleSignInAccount gSignInAccount = 
        gSignInResult.getSignInAccount();
        gnombre = gSignInAccount.getDisplayName();
        gapellido = gSignInAccount.getFamilyName();
        gcorreo = gSignInAccount.getEmail();
        gfoto_url = gSignInAccount.getPhotoUrl().toString();
        Glide.with(this).load(gfoto_url).into(gfoto);
    }
    else
    {
        Toast.makeText(getApplicationContext(),"Usuario o contraseña 
        incorrecta",Toast.LENGTH_LONG).show();
    }
 }

What's wrong?

Thanks

0

There are 0 best solutions below