2016-07-17 63 views
0

單擊從谷歌登錄登出時的Android強制停止。單擊從谷歌登錄登出時的Android強制停止

時,在註銷按鈕我的應用程序的用戶點擊,然後我打電話功能confirmationbox,如果用戶點擊yaok所以用戶將註銷,但現在它強制停止當用戶點擊yaok

這是我的代碼

private void confirmationBox() { 
     final AlertDialog.Builder builder = new AlertDialog.Builder(this); 
     builder.setMessage("Apakah Anda Yakin?") 
       .setCancelable(false) 
       .setPositiveButton("Ya", new DialogInterface.OnClickListener() { 
        public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) { 
         Auth.GoogleSignInApi.revokeAccess(mGoogleApiClient).setResultCallback(
           new ResultCallback<Status>() { 
            @Override 
            public void onResult(Status status) { 

            } 
           }); 
         session.logoutUser(); 
         Intent intent = new Intent(getApplicationContext(),LoginActivity.class); 
         startActivity(intent); 
         finish(); 
        } 
       }) 
       .setNegativeButton("Tidak", new DialogInterface.OnClickListener() { 
        public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) { 
         dialog.cancel(); 
        } 
       }); 
     final AlertDialog alert = builder.create(); 
     alert.show(); 
    } 

GoogleSignInOption

private void setGoogleSignInAccount() { 
     // Configure sign-in to request the user's ID, email address, and basic profile. ID and basic profile are included in DEFAULT_SIGN_IN. 
     GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 
       .requestEmail() 
       .build(); 

     // Build a GoogleApiClient with access to the Google Sign-In API and the options specified by gso. 
     mGoogleApiClient = new GoogleApiClient.Builder(this) 
       .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */) 
       .addConnectionCallbacks(this) 
       .addOnConnectionFailedListener(this) 
       .addApi(LocationServices.API) 
       .build(); 
    } 

,這是我logca t

07-17 10:47:55.871 26064-26064/com.emergency.e_place E/AndroidRuntime: FATAL EXCEPTION: main 
                     Process: com.emergency.e_place, PID: 26064 
                     java.lang.NullPointerException: Appropriate Api was not requested. 
                      at com.google.android.gms.common.internal.zzx.zzb(Unknown Source) 
                      at com.google.android.gms.common.api.internal.zzj.zza(Unknown Source) 
                      at com.google.android.gms.common.api.internal.zzg.zza(Unknown Source) 
                      at com.google.android.gms.common.api.internal.zzg.zzb(Unknown Source) 
                      at com.google.android.gms.common.api.internal.zzl.zzb(Unknown Source) 
                      at com.google.android.gms.common.api.internal.zzj.zzb(Unknown Source) 
                      at com.google.android.gms.auth.api.signin.internal.zzc.revokeAccess(Unknown Source) 
                      at com.emergency.e_place.MainActivity$10.onClick(MainActivity.java:832) 
                      at android.support.v7.app.AlertController$ButtonHandler.handleMessage(AlertController.java:153) 
                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                      at android.os.Looper.loop(Looper.java:146) 
                      at android.app.ActivityThread.main(ActivityThread.java:5511) 
                      at java.lang.reflect.Method.invokeNative(Native Method) 
                      at java.lang.reflect.Method.invoke(Method.java:515) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) 
                      at dalvik.system.NativeStart.main(Native Method) 
+0

'相應的API並沒有requested' - 你有沒有研究這意味着什麼? –

+0

是的,我有,但不明白 –

+0

請告訴我如何聲明GoogleSignInOptions –

回答