我这样初始化我的Google Play服务客户端:
public class MyApplication extends Application implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener
protected synchronized GoogleApiClient buildGoogleApiClient() {
return new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
/* GoogleApiClient.ConnectionCallbacks */
@Override
public void onConnected(Bundle bundle) {
Log.v(TAG, "Google play services connected.");
boolean isConnected = mGoogleApiClient.isConnected(); // - this is true
boolean isLocAvailable = LocationServices.FusedLocationApi.getLocationAvailability(mGoogleApiClient).isLocationAvailable();
// this causes NullPointerException because getLocationAvailabality() returns null. WHY ????
.
.
.
}
}
Google Play服务库版本为Rev.24。 为什么会出现空指针异常? Google API客户端已初始化,连接正常,一切都符合文档要求?存在WiFi连接...