简体   繁体   中英

andengine Google Plus Sign Button

I am trying to impement Google Plus Sign Button on my android application that uses andengine and I am getting a NullPointException. Here is my code

public class GameActivity extends BaseGameActivity implements ConnectionCallbacks,          OnConnectionFailedListener{

public static GameActivity gameActivity;
public static ProgressDialog mConnectionProgressDialog;

public static PlusClient mPlusClient;
public static ConnectionResult mConnectionResult;
private static final int REQUEST_CODE_RESOLVE_ERR = 9000

public void onCreate(Bundle savedInstanceState) {
gameActivity = this;
}

public static void buttonPressed() {
    Log.e("pushNotification", "buttonPressed");
    if (!mPlusClient.isConnected()) {

        if (mConnectionResult == null) {
                mConnectionProgressDialog.show();
            }

        try {

               mConnectionResult.startResolutionForResult(gameActivity,REQUEST_CODE_RESOLVE_ERR);
            } catch (SendIntentException e) {
                mConnectionResult = null;
                mPlusClient.connect();
            }
    }

}

The static method buttonPressed is called on my Menu Scene. It works well untill it crashes on the line with the code:

mConnectionResult.startResolutionForResult(gameActivity, REQUEST_CODE_RESOLVE_ERR);

as I posted, it is called on the "try" part.

Does any one can help me? What I am doing wrong? What parameter do I have to pass instead of "gameActivity"??? Many Thanks

run your buttonPressed() method on UI thread as follows:

 Activity.this.runOnUiThread(new Runnable() {

            @Override
            public void run() {

                buttonPressed();
            }
        });

Try this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM