1

如果我在凭据窗口刚开始出现时单击它,则会收到空指针异常。我的代码:

if (googleApiClient == null) {
    googleApiClient = new GoogleApiClient.Builder(getActivity())
          .addOnConnectionFailedListener(this)
          .addApi(Auth.CREDENTIALS_API)
          .build();
}

if (!googleApiClient.isConnected()) {
    googleApiClient.connect();
}

if (hintRequest == null) {
    hintRequest = new HintRequest.Builder()
            .setHintPickerConfig(new CredentialPickerConfig.Builder()
            .setShowCancelButton(true)
            .setShowAddAccountButton(true)
            .build())
            .setEmailAddressIdentifierSupported(true)
            .build();
}

PendingIntent intent = Auth.CredentialsApi.getHintPickerIntent(googleApiClient, hintRequest);

try {
    getActivity().startIntentSenderForResult(intent.getIntentSender(), RC_HINT, null, 0, 0, 0);
} catch (IntentSender.SendIntentException e) {
    Timber.w("Could not start hint picker Intent", e);
}

这是我使用结果的地方:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == RC_HINT) {
        if (resultCode == Activity.RESULT_OK) {
            Credential googleHintCredentials = data.getParcelableExtra(Credential.EXTRA_KEY);

            // if not null then use the data
        }  else {
            Timber.w("Hint Read: NOT OK");
        }
    }
}

我经常收到这个堆栈跟踪:

Process: com.google.android.gms.ui, PID: 27143 java.lang.RuntimeException: Unable to destroy activity {com.google.android.gms/com.google.android.gms.auth.api.credentials.ui.CredentialPickerActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.util.ArrayList.size()' on a null object reference
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3831)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3849)
at android.app.ActivityThread.-wrap5(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1398)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.util.ArrayList.size()' on a null object reference
at com.google.android.gms.auth.api.credentials.ui.CredentialPickerActivity.onDestroy(SourceFile:393)
at android.app.Activity.performDestroy(Activity.java:6422)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1142)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3818)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3849) 
at android.app.ActivityThread.-wrap5(ActivityThread.java) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1398) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:148) 
at android.app.ActivityThread.main(ActivityThread.java:5417) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

任何想法可能是什么原因?

4

0 回答 0