GameHelper crashes on onConnectionFailed()

前端 未结 2 332
清酒与你
清酒与你 2021-01-12 04:09

I\'ve got the following crash in GameHelper.java:

[main] java.lang.NullPointerException at com.google.android.gms.common.Connection

相关标签:
2条回答
  • 2021-01-12 04:33

    EDIT:

    This now has been fixed in latest GameHelper version: https://github.com/playgameservices/android-samples/commit/e7b3758c136b5b434f1dfd9ca8c03f75aad70f09

    OLD ANSWER:

    For me it happens on the start of the app, when Google Play Services asks me to sign in and if I click cancel, this same error happens.

    So when leaving from your own activity to sign in activity, it dispatches onStop event, and fails to connect because of the user initiated process, which is resolvable, thus the error happens.

    So my quick hack was changing:

    catch (SendIntentException e)
    

    to simply

    catch (Exception e)
    

    So it would also catch Null pointer exception Of course in this case the signup process might not proceed, so I initate relogin on another action and it seems to work for now.

    More thorough hack could be trying to resolve the result on activity start, for that we define pending resolution variable:

    // Are we expecting the result of a resolution flow?
    boolean mExpectingResolution = false;
    boolean mPendingResolution = false;
    

    Then on the error line we check if activity is not null

    if(mActivity != null)
        mConnectionResult.startResolutionForResult(mActivity, RC_RESOLVE);
    else
        mPendingResolution = true;
    

    And on start we check and try to resolve it:

    if(mPendingResolution && mConnectionResult != null)
    try {
        mConnectionResult.startResolutionForResult(mActivity, RC_RESOLVE);
    } catch (SendIntentException e) {
        e.printStackTrace();
    }
    

    This should help until the official resolution from lib supporters :)

    0 讨论(0)
  • 2021-01-12 04:36

    Today is 16th september 2014 and I still facing this problem.

    I don't know why anyone else did not answer about to comment GameHelper line. In onStop method there is a line to set mActivity variable as null.

    I commented this line (like below) and my app is working properly.

      /** Call this method from your Activity's onStop(). */
    public void onStop() {
        debugLog("onStop");
        assertConfigured("onStop");
        if (mGoogleApiClient.isConnected()) {
            debugLog("Disconnecting client due to onStop");
            mGoogleApiClient.disconnect();
        } else {
            debugLog("Client already disconnected when we got onStop.");
        }
        mConnecting = false;
        mExpectingResolution = false;
    
    
    
        // let go of the Activity reference
        //mActivity = null;  //COMMENT THIS LINE!!!!
        //COMMENT ABOVE LINE
    }
    

    Is there any problem doing that:?

    0 讨论(0)
提交回复
热议问题