我有像这样的代码setGoogleSignInAccount
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
我有使用FusedLocationApi
这样的
Location mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
mGoogleApiClient);
并且它的工作正常,但我现在的问题是,当我点击退出错误时.addApi(LocationServices.API)
当我更改为.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
时,退出成功,但现在FusedLocationApi
是错误
和FusedLocationApi
错误
07-17 11:58:16.763 26607-26607/com.emergency.e_place E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.emergency.e_place, PID: 26607
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.location.LocationServices.zzi(Unknown Source)
at com.google.android.gms.location.internal.zzd.getLastLocation(Unknown Source)
at com.emergency.e_place.MainActivity$1.onClick(MainActivity.java:166)
at android.view.View.performClick(View.java:4646)
at android.view.View$PerformClick.run(View.java:19403)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
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 :(得分:1)
不要改变。加。当我更改为.addApi(Auth.GOOGLE_SIGN_IN_API,gso)时,注销成功
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
// Add more APIs, as needed
.build();