androidgoogle-play-servicesgoogle-play-gamesgoogle-api-clientgoogle-plus-one

Force close on GoogleApiClient.connect()


i am clueless why my app is getting force closed on clicking the g+singin button. i have just implemented a g+ sign in button that on clicking calls GoogleApiClient.connect() method. but the app doesnt force close if i comment the GoogleApiClient.connect() method .actually if connection fails onConnectionFailed() method should be called,but force closed. I have put the error messages as image at the bottom........

package com.playservices.murali.playservices;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.games.Games;
import com.google.android.gms.plus.Plus;
import com.google.example.games.basegameutils.BaseGameUtils;


public class MainActivity extends ActionBarActivity implements
    View.OnClickListener,
    GoogleApiClient.ConnectionCallbacks,
    GoogleApiClient.OnConnectionFailedListener {
private static final String TAG = "asdf";
private GoogleApiClient mGoogleApiClient;
private boolean mResolvingConnectionFailure = false;
private boolean mAutoStartSignInFlow = true;
private boolean mSignInClicked = false;

private static int RC_SIGN_IN = 9001;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    findViewById(R.id.sign_in_button).setOnClickListener(this);
    findViewById(R.id.sign_out_button).setOnClickListener(this);
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
            .addApi(Games.API).addScope(Games.SCOPE_GAMES)
            .build();
  }

@Override
protected void onStart()
{

}

@Override
protected void onStop()
{

}
@Override
public void onConnected(Bundle bundle) {
}

@Override
public void onConnectionSuspended(int i) {

}

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {

}

@Override
public void onClick(View view) {
    if (view.getId() == R.id.sign_in_button) {
        // start the asynchronous sign in flow
        mSignInClicked = true;
        mGoogleApiClient.connect();
    }
    else if (view.getId() == R.id.sign_out_button) {
        // sign out.
        mSignInClicked = false;
        Games.signOut(mGoogleApiClient);

        // show sign-in button, hide the sign-out button
        findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
        findViewById(R.id.sign_out_button).setVisibility(View.GONE);
    }
}

}

this is error message shown to me


Solution

  • Try porting my code into yours http://pastebin.com/gAspppbh you hav pretty much left out some stuff!